It could be because you're binding a function to the buttons each time buy_ship is called. So the second time you call buy_ship. The previous binding is still there.
window.stackedWidget.setCurrentIndex(4)
window.btn_buy.clicked.connect(purchase)
window.btn_back_to_SY.clicked.connect(cancel_purchase)