I have been down either this precise same road or one very similar. Actually, two roads.
Road #1: I bought what was represented to me to be a '98 4wd transmission. It was in fact a '97, or perhaps even earlier transmission. I took the trouble to have it rebuilt too. Paid a guy to mount the "new" transmission (and xfer case) into my 2wd XJ. got a call from him saying that the connector -- the one from the transmission to a place under the hood, near the rider's firewall, close to the heater blower would not work. Has maybe 6 or eight conductors. The one in the jeep was a different color than the one from the trans. No problem, I thought. I'll just fix the wires. WRONG. I will post a helpful thread at the end of this comment. The one had I read it, I could have saved about $2,000 all told.
Road # 2: When I plunked down money for a 'known' 2000 transmision and for its installation, even though the electrics looked OK (and as it turns out, were) I got pretty much the same symptoms as you got. This time the fix was simpler and lots cheaper: I live in North Florida where "mud daubers" (Sceliphron caementarium) ae commonplace, and one place they love to daub is/are transmission vent hoses. That produced for me the exact symptoms you are experiencing. When I would fill the transmission with fluid, a few quarts would go in until the air pressure in the transmission would permit no more to enter the transmission. To make things slightly worse, the fluid on the dipstick would show the trans to be overly full. But in fact, it has less fluid than it took to function properly. I cleared the vent hose, topped off the trans fluid and have not had a transmission issue since.
Back to raod #1: your '95 XJ almost certainly has a transmission (not the same as the engine ECM) computer, connector and associated wires that don't know what to do with an input shaft speed sensor signal Toward the end of production in '97, the AW4 sports such a sensor. And there are other differences as well. You can fix it with a manual shift kit, or you can shift it manually, if you don't really need second. BTW,, figuring which transmission you have takes about five seconds: Crawl under your XJ from the drivers side. About half way up on the transmission, no more than an inch or so behind the joint between the transmission, you will either see a hole in the transmission for a sensor, or you will see a boss for a sensor, but no hole for it to fit through. And there will be a boss for the little bracket that would secure the sensor to/in the transmission, if it had a sensor. That boss will NOT have threads cut in it.
Here's the thing: Perhaps whoever sold you the '95 transmission may have sold you a '98 transmission. If I prayed I'd pray for you a mud dauber scenario.
Here is an excellent thread on the AW$. The author gets to the problem you may be facing on the first page. Good luck, I do hope you have better luck than I did with a remedy to your issue. The Thread:
https://www.naxja.org/forum/showthread.php?t=1053970
Lastly: If I had a nickel for every friend, collogue, enemy, etc who said: "Harold: if you wanted a 4X4 why didn't you just buy one?" Well had I followed their advice I would have enough nickels to fill the back of my shitbox, and enough to fill yours too. However many nickels there are in about $2500.