If you had to choose one of these two. Which would you choose for 2 days? Family trip.
That's very difficult to answer because everyone is different. And comparing Baden-Baden to Heidelberg is like comparing apples to oranges. Baden-Baden is a town in the Black Forest that is known for its natural hot thermal springs, and can get very crowded in the summer. Heidelberg, on the other hand, is a beautiful city set in a lovely setting and with a lot of history and interesting architecture.
They're both worth a visit, but if you can only choose one, pick the one that interests you the most. I would definitely pick Heidelberg, but that's me. I like cities and I like history and I like architecture. You do you and choose what interests you. If you like relaxing in a hot spring and staying in the Black Forests with lovely scenery and other small towns to visit, then go for it, but if you'd rather see an interesting city with a lot of history, then go for Heidelberg.
So basically, please tell us when you will be there, how many are going, and what the respective approximate ages are (i.e. two adults plus two teenagers, et cetera). And let us know what your interests are. The more information you give us, the better an answer we can give you.
Heidelberg, hands down. It's not Germany's greatest city, nor is the castle there terribly interesting, but it does have an enjoyable and mostly well-preserved old-town zone as well as a fun "Bergbahn" to the peak that overlooks the immediate area:
https://www.bergbahn-heidelberg.de/en/Home/Welcome-to-the-Heidelberger-Bergbahnen.html
And nearby are some nice places to visit...
Hirschhorn: https://img.fotocommunity.com/hirschhorn-am-neckar-a65c6bd3-3a61-4461-992a-1cba6afa5e9e.jpg?height=1080
Bad Wimpfen: https://www.visit-bw.com/en/article/old-town-bad-wimpfen/8502d11c-49cf-4259-8727-d4e7a269aab9#/
Burg Guttenberg: https://burg-guttenberg.de/en/
Baden-Baden's bread and butter depends on gambling, spa treatments, and high-end shops. And visiting other towns from there by train is very peculiar - it requires a preliminary 20-minute bus ride just to reach the town's train station. (And of course you have that same bus ride to get to the town center in the first place when you arrive at Baden-Baden station.)