Jesus taught his disciples to pray in private (Matthew 6:6 when thou prayest, enter into thy closet, and when thou hast shut thy door, pray to thy Father which is in secret)? Why then do people pray in God's house (Matthew 21:13 My house shall be called the house of prayer), with others in a small group (Acts 1:14 These all continued with one accord in prayer and supplication, with the women, and Mary the mother of Jesus, and with his brethren), by a river (Acts 16:13 on the sabbath we went out of the city by a river side, where prayer was wont to be made), on the seashore (Acts 21:5 we kneeled down on the shore, and prayed) and everywhere (1 Timothy 2:8 I will therefore that men pray every where, lifting up holy hands, without wrath and doubting)?
The context of Jesus’ instructions regarding private prayer (when thou prayest, thou shalt not be as the hypocrites are: for they love to pray standing in the synagogues and in the corners of the streets, that they may be seen of men) and these other examples show that he did not teach us about one exclusive place for prayer, but rather to highlight what our motive ought to be in prayer. Hypocrites pray to show off. If we are uncertain that our motive may be to show off spiritually or promote ourselves as super-spiritual, then it would be better to pray in private. In fact Jesus himself prayed in public but from a different attitude of heart. His motive was for the benefit of others, that they may believe (John 11:1-45 Jesus lifted up his eyes, and said, Father, I thank thee that thou hast heard me. And I knew that thou hearest me always: but because of the people which stand by I said it, that they may believe that thou hast sent me). The pastoral prayer follows Jesus' example. It is not meant to be a time to show off but as encouragement for others to believe.
So, when we pray in public, let us ask ourselves whether our motive is to promote ourselves or God.
All Bible quotes: King James Version public domain
Pray in secret
Jesus said to pray in secret, in our closet or private room rather than pray like the hypocrites to be seen of men. The key here is the motive, not the place of prayer. If our motive is wrong, then it is better to pray in secret rather than have a wrong motive.
Just as Christians today pray in church, early Christians prayed on a river bank, on the seashore and in private homes. The point Jesus was making was not that it is wrong to pray in these places, but that our motive ought to be not one of self-aggrandizement or that of a religious show off.
Jesus prayed in public
Jesus prayed in public, not to contradict himself, but with a different motive than that of they hypocrites. He was not a religious show off, or a show pony, like those who like to trumpet themselves. His motive was pure, to inspire those who heard his prayer that they may believe.