TO220 and D2PAK are almost the same package. Internally the die is soldered and electrically connected to the heatsink tab. So electricallt the substitute can be made.
I actually knew a guy who modified TO220 ti SMD by cutting of the tab and forming the leadS by hand. Can't say this is recommended due to risk of damage to the device though.