Getting a bike fit is a good idea. Start there. That said, it IS a common and fairly well-documented problem among cyclists and is sometimes too easily dismissed as just a bad bike fit or, worse, lack of core strength. (“Do your core training!” almost as in “It’s your own fault!”)
But in some cases it’s just a matter of a vulnerable and sensitive ulnar nerve. Some people get it, some don’t. Some people get back problems on a bike, some don’t no matter how aggressive their rider position, because their back isn’t so sensitive. Some office workers get severe problems with the median nerve, another of the three main nerves that go through the wrist, elbow and shoulder, and so they get carpal tunnel syndrome, while others work for years with bad ergonomics and are totally fine.
You can get surgery for ulnar problems but the success/improvement rate doesn’t seem to be that great and you can even go from bad to worse (I know of people who did).
Adjustments to seating position (angles of wrists and elbows), stem length, handlebar width as suggested above, can help. But more than anything it comes down to saddle-to-bar drop. Too aggressive a position and weight gets shifted forward, no matter how strong your core is, and that will make the problems worse. So an endurance frame is a good choice since they tend to have a higher stack-to-reach in the frame geometry. But apparently that isn’t enough in your case, at least not indoors which is always a bit rougher in some ways because you are more static, the road doesn’t bump you around and you pedal all the time.
With adjustments and with more training over time, seeing as you recently got started (don’t strain yourself too hard though, increase ride length gradually) things may get better. But chances are still that your ulnar nerve will always be a weak spot in you. It is for me. I had zero hand problems as a teenage rider. Returning to the bike many years later and I am suddenly sensitive. Gradual adaptation has made it better but put me on an unusually long ride with a headwind forcing me to stay in the drops and it’s there.
Try things out, but as a worst case scenario:
Not sure, but I’m guessing these kind of hand problems are less common among X-country MTB riders (they get other hand problems instead) because of their more upright position. A very aggressive road racer position isn’t better from a power output perspective, it’s just more aerodynamic and hence faster. So if you don’t care too much about outdoors or if you want both but can afford a Zwift bike for the trainer, get something considerably more upright. Or do the full switch to MTB instead. That will make a difference for sure.