You just have to make sure the YJ transfer case came out of a YJ that has the same 2.5L engine and transmission yours has. If yours has the 5-speed, the t-case has to have come out of a YJ that had a 5-speed.
The reason for that is so the input and output shaft spline counts will match and their lengths will be the same.
That said, the YJ 231 is not as good as the TJ 231 in a few ways like the fact it will leak with the rear driveshaft removed. I personally would hold out for a transfer case out of a TJ.
And I'm not so sure the YJ's t-case has a true neutral for the front driveshaft when you're in 2wd. That is the reason for, I believe, the YJ's need for its passenger-side vacuum operated axle unlock mechanism so it will steer ok in 2wd and why the TJ doesn't need the YJ's front axle disconnect.