R&A rule 13.2c:

Flagstick - Ball resting against flagstick in hole
This Rule applies to a ball played from anywhere on the course, whether on or off the putting green.If your ball comes to rest against the flagstick left in the hole:
  • If any part of your ball is in the hole below the surface of the putting green, your ball is treated as holed.
  • If no part of your ball is in the hole below the surface of the putting green, your ball is not holed and must be played as it lies. If the flagstick is removed and your ball moves there is no penalty and it must be replaced on the lip of the hole.