Low flying A/C spotted you and radioed your location to him or, the destroyer was manned by crew of eagle eyed carrot eating sailors who spotted your scope or, the rabbit eared hydrophone operator on the destroyer picked you up.
I really do not know why it happens, it just does, frustrating, but it does happen. It does however teach us to never let our guard down or, take anything for granted.