Praise be to Allah.
It is not permissible for a non-Muslim to pray either in the ranks or on his own. What he has to do is to enter Islam before he prays, then to purify himself [by doing ghusl], and then fulfil the conditions of prayer.
He is includes in the obligation of prayer, and he is to be punished if he does not become Muslim and pray, but it will not be accepted from him unless he enters Islam.
Allaah says (interpretation of the meaning):
“And nothing prevents their contributions from being accepted from them except that they disbelieved in Allaah and in His Messenger (Muhammad)”
“If you join others in worship with Allaah, (then) surely, (all) your deeds will be in vain, and you will certainly be among the losers”
Shaykh Ibn ‘Uthaymeen said, when listing the conditions of prayer being valid:
There are other conditions which include: being Muslim, being of sound mind, and having reached the age of discretion… No act of worship is valid unless one is a Muslim, of sound mind and has reached the age of discretion, apart from zakaah, which is obligatory upon the insane and minors, according to the correct opinion. With regard to the validity of Hajj performed by a minor, there are texts which state that it is valid.
Al-Sharh al-Mumti’, 2/95, Ibn al-Jawzi edition.
And he said:
The conditions of prayer are: being Muslim, being of sound mind, and having reached the age of discretion; that the time for prayer has begin; covering the ‘awrah; having purified oneself from anything that invalidates wudoo’; avoiding najaasah (impurity); facing the qiblah; and having the intention of praying.
Al-Sharh al-Mumti’, 2/289, Ibn al-Jawzi edition.
The same applies to the other acts of worship; they can only be accepted from a Muslim, so Islam or being a Muslim is a condition of acts of worship being valid, and their being accepted depends on that.
Ibn Rushd said:
The conditions fall into two categories:
The conditions of it being valid, and the conditions of it being obligatory. With regard to the conditions of it being valid, there is no difference of scholarly opinion that they include being Muslim, because Hajj is not valid if done by one who is not a Muslim… End quote.
Bidaayat al-Mujtahid, 1/133
And Allaah knows best.