We moved to Nürnberg for a 1.5 years stay on our daughter's first birthday. We have visited the Stuttgart area 3 times in recent years. There is a wealth of things to see by rail in the area of each. You can not go wrong.
You know your kids best but we had lousy luck guessing what would impress our daughter while stationed in Germany. We took her to Legoland and it was a bust. We took her to the zoo in Vienna and, once she found that elephants were huge and smelly, that also became a bust. She was fascinated that they painted pictures on the ceiling of churches. She loved riding in her folding stroller in rain because we let her hold her own umbrella. Reading to her at bed time was a big event most travel days. It was more how we included her than what we visited.
There is a Fairy Tale Garden as part of the Palace Gardens in Ludwigsburg that probably would have appealed to our daughter as she loved the outdoors. Ludwigsburg is just a 10-15 minute train ride out of Stuttgart.