The only way you can get attacked during the same turn and sieged is if you get an indie event like barbarians on the same turn as you storm the castle. Or if you had one sometime during the siege, because that invokes a specific bug.
The province I was in was attacked by barbarians the same turn as I stormed the castle - ended up with my forces inside (yay!) and the barbarians laying siege. Last mistake they ever made.