The only and simple thing you have to do is /hat while you have the banner in your hand.
To get it off, you simply open your inventory and take it off, then put it back in your inventory.
You can also use blocks as hats and more! (little detail; you won’t be able to use 2 blocks or banners at the same time)
¡Hope you have a good day and found this information useful!