What a trip! Sadly, I got stucked in front of the castle too.
Jump to the opposite direction and change direction while in the air so that the door won't trigger.