All perfect praise be to Allah, The Lord of the worlds. I testify that there is none worthy of worship except Allah and that Muhammad is His slave and Messenger.
It is not valid to follow the imaam when you are outside the mosque while there are places inside it, especially if you are praying by yourself. The prayer of one praying by himself behind the row without excuse is not valid even inside the mosque according to the view of some scholars. So it is with greater reason that it is not valid if it is outside the mosque.
For more benefit on the ruling on praying outside the mosque while there are places inside the mosque, please refer to fatwa 91988.
Also, for more benefit on the prayer of a person individually behind the row when he is led by an imaam, please refer to fatwa 350431.
If you are prevented from entering the mosque, you will receive the full reward of the prayer, Allah willing, and the one who prevented you from doing so is sinful.
Allah knows best.