The transmission itself will work, the lockup for the torque converter lockup is different, so some wiring work would need to be done.
Last I checked the differences are that the YJ is a 1-wire solenoid while the TJ is a 2-wire solenoid. The torque converter lockup function on YJs is controlled by the PCM grounding a relay on the firewall, which provides power to a case grounded solenoid. The TJ provides power and ground from the computer. I believe it is always grounded by the computer and the computer provides power when it wants to lock up the torque converter.
So to run the TJ solenoid on a YJ, you would need to ground the solenoid and then you could let the YJ continue to power it like stock. It's trickier the other way, using a YJ transmission on a TJ that wants to control both wires.
The TJ uses it's method because the TJ started the computer giving error codes when the torque converter doesn't lock up when the computer expects it to. The YJ throws no error codes related to the transmission. When the TJ computer controls both wires, it can sense when the converter is locked or not, so they switched to that method for 97 and on.