Sure, that's possible. As default, OBS puts audio track 1 into the stream. In Edit->Advanced audio properties, setup track 1 in a way that only audio sources without your copyrighted music get mixed onto track 1.
For recording, go to Settings->Output->Recording and uncheck track 1. Instead, check Track 2. This way, only audio track 2 gets written to your recording and not track 1. Then go to Edit->Advanced audio properties and setup track 2 similar to track 1 but add the audio source that will contain your copyrighted music as well.