According to Ayatullah Khamenei’s viewpoint on the issue, if one obtains money from the bank as mudharabah or musharakah (partnership), in the case of the transaction being simulated and not for real, the transaction is void and the bank still owns the money, thus it isn't permissible to use it. But if the transaction is for real and not simulated, the money received is a trust and cannot be used for anything other than specified.
On the contrary, if the money obtained from the bank is a loan [which your question is apparently about], the money becomes the property of the person getting the loan and can be spent on anything he/she desires. Of course, if one of the terms of the loan is for it to be spent for a specific purpose [such as buying a car or real estate etc.], the term must be met [meaning that it is wajib for the one obtaining the loan to only use it for the specified purpose and if not, he/she has committed a haram act], yet if it isn't, the transaction is valid [so, this issue has two sides to it; the first being the ruling of not fulfilling the terms of the loan, which is that it is haram, and the second being the ruling of the transaction one has done with the money of the loan, which as was said, is that the transaction is valid; therefore there is no conflict between the act being haram and its validity]. As a result, if one performs Hajj with a loan that was only meant to be used for other things, the Hajj is still valid, although one has sinned by not fulfilling the terms of the loan. One more thing that needs to be noted is that if one isn't financially qualified for Hajj to become wajib regarding him/her, and obtains a loan and performs the Tamatto’ Hajj with it, it won't be counted as the wajib Hajj for him/her [in other words, what Allah (swt) wants from us, is to perform the wajib Hajj when we can afford it with our own money, without the help of a loan, therefore if it hasn’t become wajib for us and yet we perform it, it is counted as a mustahabb Hajj, therefore, if we ever reach a point that we can afford it with our own money, it still becomes wajib, and the one performed with the loan can't take its place].