gh-38706: better subs on piecewise functions
This will allow to change variable for another variable in piecewise
functions.
This will fix #22102
### :memo: Checklist
- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [x] I have updated the documentation and checked the documentation
preview.
URL: https://github.com/sagemath/sage/pull/38706
Reported by: Frédéric Chapoton
Reviewer(s): Travis Scrimshaw