To answer the question of why the Ahlulbayt (a) were chosen for purification and if this is in line with justice of Allah, certain aspects must be understood properly.
1) What is meant by the Justice of Allah? Justice of Allah is not separate from His wisdom. That means that all His actions, in existential and legislative matters, are in line with the highest wisdom, for the good of all His creatures. Justice of Allah also means He would not do anything wrong such as oppression. He creates each creature with its own capacity, potential, etc. and expects from it accordingly. Justice is that He does not demand from any creature more than what the creature can do.
2) There exists different capacities and potential among the creatures. He did not create everyone the same, that is not part of the perfect system He designed. This is in line with His justice and wisdom as it is best for the functioning of this world. The differences are not a sign of injustice. Rather, it is justice because different levels of understanding and abilities are needed for society to flourish and remain like a body with different organs, each of them contributing to the overall needs of the body.
3) The focus for success in this world and the hereafter for each person is to recognize the talent and potential given to him/her so they can use it to achieve perfection in God’s way.
4) The different levels between the creatures are not a discrimination. It is not that some people get everything and some are overlooked. Every creature gets, according to His wisdom. Ayatullah Mutahhari explains this with the following example. If you take two containers which can hold 10 litres (L) of water and fill one with 10 L and one with 5 L, that would be discrimination. But if you have one container that can hold 10 L and you put 10 L in, and the other container can only hold 5 L and you put 5 L in, you dealt with them differently according to their capacity.
5) People who are pure and virtuous are of two types. One are the Mukhlisin, those who have accepted the commands of Allah (s) and work hard to obey Him. They are sincere and do good deeds. It is through their efforts that they have reached a certain rank with Allah (s). They were not chosen to be like that, they became like that. There is another group that includes the Prophets and the Masumin (a), who receive extra abilities from Allah (s) and are Mukhlasin, purified by Allah (s). They also go through stages of striving for perfection and hard struggles, and earn the additional perfection and purification. This was in order for them to be worthy of carrying out the responsibility of guiding people to Allah (s). This huge responsibility is only given to those who show high levels of perfection from themselves and God adds to it. God knows who is more worthy of such a position due to His comprehensive knowledge and chooses them accordingly. He says in the Quran; And We made of them Imams to guide by Our command when they were patient, and they were certain of Our communications (32:24) and Allah (s) knows best where to place His apostleship (6:124).
The following excerpt at the beginning Dua al-Nudba also explains it; Your vicegerents whom You have purely selected for Yourself and Your religion . . . after You had already stipulated on them to renounce all the ranks of this lowly world along with all of its embellishments and ornaments, and they accepted this stipulation. As You knew that they would fulfill this stipulation, You accepted and drew them near to You. You thus provided them with sublime mention and obvious approval, made Your angels descend to them, honoured them with Your revelations, supported them with Your knowledge, and made them the channel to You.
6) To choose certain people for certain roles in life is not injustice. Every creation, from the angels and the jinns to the humans all have a certain role to play in existence. Each is equipped with what they need to fulfill that role and will be responsible for the role they have been assigned. That is a perfect system, based on justice.