From the Super Mario Wiki
Scarecrows are objects that first appear in Super Mario Odyssey and they are found in all kingdoms except the Cloud Kingdom and Ruined Kingdom. Mario must throw Cappy towards it to open a doorway to a sub-level for a Power Moon, activate Timer Challenges that require Mario to reach a Power Moon on a few platforms using his acrobatics only, or for a few other uses. Cappy will cling onto the Scarecrow once thrown upon; consequently, Mario must then venture on without him.
These sub-levels (in which Mario will have to reach the Power Moon without the help of his companion) are similar to the ones in Super Mario Sunshine, where every now and then Mario is separated from F.L.U.D.D., requiring the player to trust on Mario's acrobatic skills. Although, in Super Mario Odyssey it is repeatedly obligatory for Mario to get into the sub-levels without his companion (in this case, Cappy), whereas in Super Mario Sunshine, once the secret level has been cleared, Mario doesn't have to anymore.
Given the fact that Mario can no longer use Cappy's abilities when thrown upon the Scarecrow, simply walking away or jumping upon the Scarecrow gets Cappy back in his possesion.