We put this question to Shaykh Muhammad ibn Saalih al-‘Uthaymeen, may Allaah preserve him, who answered as follows:
As for the beggars who stand outside the doors of the mosque, there is nothing wrong with giving to them if they are genuine, but it is not allowed for them to do that inside the mosque, and they should be stopped and told, “Go and stand outside the door.”
Would the imaam who tells them to go outside be considered to be going against the Aayah (interpretation of the meaning): “And repulse not the beggar” [al-Duhaa 93:10].
He is not repulsing him, he is just telling him to move to a different place. And Allaah knows best.