Offering prayer inside the Ka’bah is a Sunnah act of the Prophet (peace be upon him). It is recommended to do so if possible in our present time.
However, if one is unable to do it, the Haj is valid.

It is recommended to perform prayer inside the Ka’bah if one is able to do it without inflicting hardship on himself or others. It is reported that the Prophet (peace be upon him) did so and said, “I fear that I have placed difficulty on my Ummah.”

When A’ishah asked the Prophet (peace be upon him) about offering prayer inside the Ka’bah, he said, “Pray in Al-Hijr, for it is a part of it.”

These texts indicate that such an act is a deed that fetches great reward. However, a Muslim should not harm others in order to get in there.

Upon entering the Ka’bah, a Muslim is recommended to pray two rak’ahs and say “Allah-o-Akbar” and make as much dua (supplication) as he can, for by doing so he is following the guidance of the Prophet (peace be upon him).