"Is it necessary to practice staying in time while improvising?"
Nothing is "necessary" in this context. Improv is improv, even time and tempo fluctuate during improvisation, as well as in orchestrated pieces. The real question is whether you are in control of what you do. In my youth I often heard young musicians respond to their own playing after a solo with "I didn't expect that", or "Wow, that sounded cool". Improv from an experienced player should not be a complete surprise. Sometimes we go in directions we didn't intend to in response to other player's input but the fact is improvising draws on examples that are already in the player's consciousness, and variation on themes already present in the music.
That being said a bigger issue, and a more important question is not one of keeping time but keeping track of where you are in the song as you improvise. This is critical. At a high level of development a musician might be able to recall the melody of the tune in their mind as they play over it. At the very least you should be able to remember the basic structure of the tune. Are you in the A section or B section, etc.
If you are truly exploring creative ideas free form then there is no reason to be concerned about where you are since you are likely composing as you go. But to be a player in a group you really do need to be able to keep time by yourself and know where you are in a piece. Experienced musicians can sometimes recall tempos without the help of a metronome. Two examples are (1) my classical bass teacher in high school (who was perhaps a savant) could tap 84 bpm on a metronome and it would read 84 +/- a couple beats, and (2) a marching band director for a bagpipe group. He could march to 78 bpm right on the nose every time. It was in his muscle memory. This is an expected skill of an experienced musician (to some degree). As my big band conductor used to say "everyone counts", and that was meant to be taken as direction.
I'd say it is very important to learn to stay in time on your own as well as recall the structure of a tune and know where you are at to the beat. There are way to practice this.
(1) try listening to a metronome and tap to it, close your eyes and mute the metronome. Then after some time un-mute it and see how close you match it.
(2) learn a tune you really like and see if you can recall it from memory in your mind without playing.
(3) play with recorded pieces, even if you don't know the piece just try to keep up in key by adding a small supportive part.