There is an Apple Music setting that controls this functionality. If you don't want the songs to be added to your Library, make sure the setting is turned off.
You can find it here: Settings → Music → Add Playlist Songs to My Music.
If you do want the songs to be added to your Library, make sure the setting is turned on.