This may be fun, and could be cool, but can wreak havoc with balance
The game term for a Hydra is "monstrosity" which is a stronger term than "a magical animal."
Monstrosity ... frightening creatures that are not ordinary, not truly
natural, and almost never benign. (MM p. 7)
When you look at how to control or train such a creature, consider the following:
- Dominate Beast is a 4th level spell that lasts for a minute, with
concentration. (PHB p. 234-235)
Dominate Monster is an eighth level spell that lasts for up to an
hour, with concentration. (8 hours if you use a ninth level spell
slot). (PHB p. 235)
Getting control of the Hydra for other than a short duration is equivalent to something more powerful than an 8th level spell. Is that balanced for your party?
Hydra is a Challenge Rating (CR)8 monster. This means that it's a
medium difficulty encounter for 3 or 4 8th level player characters.
Going backwards with that: adding this monster to the party is like
adding about two 8th level characters to the party.
How does that influence in-game balance?
Control versus some other relationship
Consider the challenge for "Animal Handling" checks
Animal Handling. When there is any question whether you can calm down a domesticated animal, keep a mount from getting spooked, or intuit an animal’s intentions, the GM might call for a Wisdom (Animal Handling) check. You also make a Wisdom (Animal Handling) check to control your mount when you attempt a risky maneuver.
This huge monstrosity has an Intelligence Score of 2, a Charisma score of 7, and a Wisdom score of 10. How well will it take instruction, since you didn't get it as a "cub?"
Tigers have an Intelligence score of 3, and are risky/hard to train
unless you make that your full time job/vocation.
A Mastiff likewise has an Intelligence of 3, but in the Mastiff description it says that it can be trained, whereas in the Tiger description (MM) no such passage is included.
The hydra presents the opposite problem with trying to use animal handling with dragons, as discussed here, so that avenue is probably a bad option.
It is not very smart
It will take a lot of effort (down time?) and resources (you can't
just feed it table scraps unless you are a Storm Giant) to
domesticate the hydra -- if that can be done at all.
How does the Ranger/Druid communicate with this monstrosity?
A "monstrosity" is not something natural. It isn't like a "beast" as animal companions are for Ranger. The CR is too high for the Ranger in any case.
Animal Friendship is a first level spell that applies to beasts, not monstrosities. It lasts for 24 hours and can make the beast believe that you mean it no harm. This kind of interaction could be the beginning of a relationship, but the spell isn't that specific. A DM could make it so ... but with monstrosities, the degree of difficulty would be higher.
What should your DM do?
Look hard at the balance problem first.
If the DM still wants to let this happen, make something up that accounts for the problems from the points above.
Consider control as being possible via a magical item. A quest for something like "The Orb of Hydra Control" (a very rare or legendary magical item) or a "Ring of the Hydra" is one way to address this if you really want to run with this hydra in the group. Reference to DMG (p. 189-190) for Ring of Animal Influence through a Ring of Elemental Command to get a sense of how to home brew such an item. (Elementals (earth, air, fire, water) are CR 5 creatures).
In a grittier world, consider how much a hydra eats and who cleans up after this thing. A comparable problem in care and feeding is an elephant.
It occurs to me (after all of the above) that if the hydra forms a relationship with a character, the DM can treat the hydra as a friendly NPC. If the DM is willing to do the work, that's another way to make this work - all other factors considered. "Rules as Fun" works as long as it is fun.