Basically, you ran into a police patrol that happened to be near the border. It could've been a random check for illegal activity (drug trafficking, etc), or they might have been looking for something in particular.
It was not a border control, and the German borders aren't more open or closed just because their police is relatively eager to do patrols. As a counterpoint, I was once stopped by German police on the highway near Hannover - far, far away from any border, and asked the same questions you were asked.
I'm from the Netherlands, and I travel into Germany many times a year, by all kinds of means of transport. I've been stopped near the border (also on a train, much like your story actually) exactly once. You just had bad luck.
Finally, while the Schengen treaty has a lot to say about freedom of movement, there's no section about welcome hugs.