I would like to know whether it is possible to be able to have a temporary root access to an android phone using a Termux or any other terminal in the same way that ubuntu does without rooting your phone.
Ubuntu for PC is permanently rooted. It comes with root user as well as with the mechanism to allow a process to gain superuser privilege when requested so and authenticated by the user (that which you considered temporary root). Android devices, on the other hand, do not provide the mechanism to gain superuser access. That mechanism, often involves installing a
su binary coupled with some daemons and hacks, provides the user a way to gain elevated privileges and manage that privilege on a per app basis.
Even if you root a device, it is not like every app or process gets to have superuser access on its own. It is the user, through a superuser manager app such as SuperSU and Magisk, who manages whether to permit temporary or permanent access to superuser privilege.
Rooting phones is usually done using root exploit scripts which day by day Google releases patches. Most of the rooting tools and scripts focus on getting permanent root but temporary root is also achieveable. However, the question you have asked is to gain root access through an Android Application like Termux which stimulates a Terminal Emulator which is not possible yet. But you can gain temporary root access nowadays if your device is atmost 7.11(Nougat) using Dirty Cow exploit but you will need PC. However, it will be temporary root access.