There is no definite answer to this.
It all depends. Generally, it is profitable to repair the gearbox, but only when one bearing breaks down or when one synchronizer is broken / worn. Replacing the gears is not economical.
In turn, buying a used one is a great unknown - everyone says that the gearbox is functional from an almost new car so much that it had an accident. The world is full of naive people who believe in words. It's a lottery.
It is bad either way. Gearbox repair is also time-consuming and in addition, not every Mirek can repair the gearbox correctly, although many declare that they will repair it. Special tools are needed, and not only a claw puller ...
Low-to-top planetary gear failure is very costly. replacing all your bearings is also a financial killer. Anyway, ZF gearboxes are quite trouble-free and if you need to replace a pair of bearings, it means that the car must have about 2 million km, and then the question arises about the sense of melting money in a wreckage ...