You could try the following:
(1) Connect the Yamaha P-45 to the Mac using a standard USB cable.
(2) Connect the Roland D-50 to the Mac using the Roland UM-ONE interface.
(3) I'm doubtful whether Garage Band will let you route MIDI from one keyboard to another. However, there's a free utility called MIDIrouter that should do the trick:
https://ask.audio/articles/midirouter-is-a-simple-app-for-routing-midi-for-mac-musicians
(4) In your DAW or MIDI router utility, select the Yamaha P-45 as the MIDI input device.
(5) Then select the Roland D-50 as the MIDI output device. (By the way, I have no idea what sort of IDs or names they'll be listed as.)
[ADDENDUM: If you're using a DAW, you will generally need to add a MIDI track and set the MIDI input and MIDI output for the track as described above-- that is, it isn't as simple as going into the DAW's configuration settings and saying you want to use one keyboard for MIDI input and another keyboard for MIDI output.]
(6) Any notes you play on the Yamaha should go to the Roland and produce notes on it as well. You might need to go into the MIDI settings for each keyboard to specify which MIDI channel to use; I haven't looked closely at their manuals, especially the manual for the D-50.
(7) If you need something more sophisticated-- specifically, something that will let you filter out any unwanted MIDI messages, such as Bank Select and Program Change-- then you might see what free or inexpensive DAWs are available. Most DAWs have some sort of "MIDI effects" plug-in that can be used to do things like filter out certain message types and Note ranges, or modify the Note values (i.e., transpose them to a different key), but that sort of functionality might not be supported in the free version of a DAW.
[ADDENDUM: (8) If you want the sounds from both keyboards to be blended together, get a mixer or something similar that will let you merge the audio from each keyboard and send the merged audio to your speakers. Otherwise, just send the audio from each keyboard to its own set of speakers.]