The same applies if he is in a state of major ritual impurity and doubts whether he has performed ghusl or not: he must perform ghusl and should not hesitate.
This—meaning basing one’s judgment on certainty and disregarding doubt—is an important principle, as indicated by the Prophet’s saying (peace and blessings be upon him): “If one of you doubts during his prayer, let him dismiss the doubt and build upon what he is certain of.” (1) It has very many subsidiary applications in divorce, contracts, and other chapters of fiqh. Whenever a person applies it, many difficulties are resolved for him, and much of his misgiving and doubt is removed. This is among the blessings of the Prophet’s words and guidance (peace and blessings be upon him).
It is also part of the ease of Islam: Allah does not want Muslims to fall into anxiety and confusion; rather, He wants their affairs to be clear and evident. If a person were to yield to such doubts, his life would become miserable, for Satan will not confine these misgivings and doubts to matters of purification alone. Rather, he will approach him regarding prayer, fasting, and other matters—indeed, every aspect of his life, even his dealings with his family. Therefore, the Lawgiver has cut off these misgivings at their root and commanded that they be abandoned and repelled, so that they leave no effect upon the soul.
If he is certain of both states but does not know which came first, ...........
His statement, “If he is certain of both states but does not know which came first,” means that he is certain that both purification and ritual impurity occurred, but he does not know which of them came first. He is then asked: What was your state before this time, during which it became clear to you that you had become ritually impure and then purified yourself?