That is always the risk buying a used car. If ANYTHING looks unusual, take it to a mechanic, you will always run into this sort of thing. I always prepare for used cars by hanging onto some of that saved up cash to take care of the problems that I already suppose it will have that are not obvious, at least NOW I do anyway
My story is very similar to yours. We were looking for a larger second car, so we settled on a Subaru Legacy Outback. Found one for the right price. I drove the car, seemed OK, former owner admitted the transmission had been replaced. It drove OK, but the tranny was a bit noisy. After a few months, the noise got worse and worse. We took it in and they said it was the wrong transmission for the car! Had to have it completely rebuilt, which ended up costing half what we paid for the car.
That's not the kicker. I looked over the car pretty well, but we didn't do a Carfax. That will never happen again. The car continued to have fairly expensive issues, so we decided to cut our losses and sell it. When we went to sell it, an interested party ran the carfax and it came back that the car had been in an accident after the former owner said it had not been, so we had to take less for the car that we just spent a bunch of money on.
Now that I've owned a few Subies, I have a better idea of what I am looking at and what is likely to go wrong with them as well as what costs the most to replace. That kind of knowledge is invaluable when looking at used cars.