If the device was disenrolled, the previous device record may still appear in the portal history. You can clear the old disenrolled device record by marking it as disenrolled from the Disenrolled Devices report.
Go to Reports > Disenrolled Devices, open the affected device entry, then use Actions > Mark as Disenrolled.
This does not cancel a script that had already reached the device, but it helps clean up the stale device record associated with the old enrollment. If the device has been enrolled again, it will be treated as a separate managed device record for future automation runs.