You can force unmount a drive by running the following Terminal command:
diskutil unmountDisk force /Volumes/VOLUMENAME
Replace VOLUMENAME with the name of a volume on the disk you are trying to unmount.
Following this, attempt to Erase/Partition the drive again in Disk Utility. Using the above command can interrupt file read/writes, which can cause file corruption. However, since you are erasing the drive anyway, this doesn't really matter in your situation.
https://apple.stackexchange.com/questions/105673/disk-utility-wont-unmount-hd-for-formatting
https://www.amsys.co.uk/disk-utility-tip-fix-couldnt-unmount-disk-errors/