This question can be answered in two parts:
A) Hajj is one of the greatest worships that one can borrow money for, and there are hadiths by the infallibles regarding the permissibility of borrowing for it in hadith sources.
B) Another issue that arises here is that since financial capability is one of the conditions of this worship becoming obligatory, will a hajj performed out of getting a loan count as the hajj that is mandatory for everyone to perform once in their lifetime? In other words, does this hajj count as the wajib hajj?
The view of many of the maraje’ regarding this question is as follows:
If one can't afford to perform hajj, and borrows money for it, he still won't be considered [religiously] capable, even if he can easily pay back the loan later. If he performs hajj with it, it won't suffice for his Hajjatul-Islam [the wajib hajj]. Of course, some marja’s, such as Ayatullahs Khu’i, Golpaygani, Fazel Lankarani, Khamene’i, Safi Golpaygani, and Zanjani believe that if someone borrows enough money to afford going to hajj and can easily repay the money, hajj will become wajib upon him.