There's definitely no rule precluding being overtaken on the last lap / corner; it's all fair game (yellow "no overtaking" flags permitting in the event of an incident). Drivers simply do this "for show" and/or to acknowledge their team who may be gathered and celebrating on the pit wall as they cross the line. It's not limited to the leader either. For example a driver finishing unexpectedly higher than normal (e.g. 4th or 5th place) may do the same thing whereas a driver who is unhappy with their finishing position would typically not (even if they were in second place).