Rules 1.5 Scoring (2) helps in understanding this situation.
1.5.3 If the ball hits the goal post, a behind is scored. This is regardless of where the ball goes after hitting the goal post, e.g., back into the field of play, through the goals or whatever. Play stops as soon as the ball hits the goal post, and is restarted by a kick-in.
And
1.6.5 (a) After a behind has scored. Any player of the defending team kicks the ball from within the kick-off 'square' in front of goal, but only after the goal umpire has finished waving his flags. The player must kick the ball out to restart play.