There is a default setting in Sonar that handles turning the Midi Input Echo on/off, as you move from one midi track being in focus to a different midi track.
So, if I have the midi track for my piano in focus (selected), Sonar will automatically turn that track's Midi Input Echo to 'on'. This makes it so I can hear the piano notes when I play notes on my midi controller.
If I then click on the midi drums track, Sonar will turn Midi Input Echo for the piano track to 'off'', and will turn it 'on' for the drums midi track. This makes it easy to move back and forth to different midi tracks, and be able to hear only the sounds you want to hear, the ones for the midi track that is in focus.
You can also manually turn Midi Input Echo on/off, and I use this approach when I want to hear a layered sound, such as piano with strings, or violins with cellos or that sort of thing.
I would imagine you have Midi Input Echo set to 'on' for more than one midi track, and have it this way from either manually setting it, or the setting in Sonar that controls it happening automatically has been turned off.
To fix the problem, click Midi Input Echo to 'off' for all the midi tracks you DON'T want to hear the sounds from while playing, and make sure the Sonar setting that automatically handles it for you is set the way you really want it.
The setting in Sonar that controls it being handled for you is in:
Edit>Preferences>MIDI>Playback and Recording, and the setting is called 'Always Echo Current MIDI Track'. Make sure this is checked if you want Sonar to handle it for you.
Bob Bone