the Rambam is in the laws of loans chapter 21 law one and law 6
This is already taking more time than I expected so I will try to make this next idea as short as possible.
It concerns the idea that on Shabat one can't do a work that is done for its own sake. (מלאכה שאינה צריכה לגופה) But if done not for its own sake this is subject to disagreement between R. Shimon and R. Yehuda
I have not written about this before here so I will at least be obligated to bring a little bit of the Gemara. R. Abahu says all types of work that do damage are not obligated in a sacrifice except for causing a wound and lighting a fire. (כל המקלקים פטורים חוץ מחובל ומבעיר)This is because the Torah allows one to do Brit Milah on Shabat. So obviously if the Torah had not allowed it it would have been forbidden [since both are among the 39 types of work that are not allowed on shabat] But why should Milah have been forbidden? It is causing a wound and doing damage! So we see causing a wound even in the case of doing damage is obligated in a sacrifice.That is all just the simple Gemara. The question is is it not also a work done not for its own sake? In fact Rashi says it is! So we see also that work done not for its own sake in the case of wounding is obligated.
What I am trying to bring out here is to nullify the other possibility that it is work done for its own sake. [צריכה לגופה] I can't prove this but I am at least showing how Rashi might answer this problem. For all I know Tosphot might say to R. Abahu that it is work done for its own sake and that is why the Torah has to allow it.