"When the Prophet (ﷺ) began facing the Ka'bah they said: 'O Messenger of Allah! How about our brothers who died while they were praying toward Bait Al-Maqdis?' So Allah Most High revealed: Allah would not allow your faith to be wasted. (2:143)"
Jami` at-Tirmidhi Book 47, Hadith 16