All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His Slave and Messenger.
If when you collected these donations you did not know that you would need this operation and no trustworthy doctor informed you that you needed it and that it was possible to carry it out, then, in this case, it was not permissible for you to collect these donations. Therefore, you do not deserve this money and you should give it back to those who gave it to you. If you do not exactly know who they are and you are not able to give it back to them, then you should spend it on the people who are eligible for Zakah.
On the other hand, if when you collected these donations you knew that you would need this operation because a trustworthy doctor informed you that you needed it and that it was possible to carry it out, and then it happened that you do not need this operation, then this money becomes your property once you owned it, and you are permitted to dispose of it as you wish, and in this case, you are not obliged to give it back as you owned it in a permissible manner.
The jurists stated that the poor person owns the Zakah once he possesses it and if he becomes solvent after possessing it, he is not obliged to give it back. Ibn Qudaamah said in his book Al-Mughni: “There are four kinds of people who permanently own the Zakah after taking it, and their situation after receiving it [i.e. if they become solvent] is of no effect , and they are: the poor, the needy, those who are employed to collect the Zakah, and those to whom Zakah was given to soften their hearts towards Islam; so whenever they take it, they permanently own it and they are not at all obliged to give it back if their conditions changed. On the other hand, there are four kinds of people: those in debt, those who spend it (Zakah) in freeing captives [or slaves], those who spend it in the Cause of Allaah (i.e. in fighting the enemies of Islam) and the [stranded] traveler; then those take the Zakah on condition that they spend it in the same purpose for which they took it; so they must spend it in the same purpose which made them eligible to receive it, otherwise the Zakah would be taken back from them.”
If a person needs medical treatment while he does not own money for paying for the treatment, then he is considered as a poor person and it is permissible for him to take the Zakah. Based on this, he takes the Zakah due to being poor and he is not obliged to give it back when he becomes solvent as he owns the Zakah immediately after taking it.
Hence, you are permitted, in this case, if the operation is cancelled for any reason, to dispose of the money as you wish, like going for Hajj with it or spending it on any other permissible matter.
Allaah Knows best.