Yes, and there are more questions about how you plan the induction, than there are answers (at this time).
The 87 head is non-HO, as is the 87 XJ Renix MPI fuel injection system. The Renix 4.0L head is a slight improvement over the YJ 258 head (better intake and exhaust ports, larger valves, better chamber design). A 91 to 95 4.0L HO head is better.
The 88 YJ 4.2 induction is one of the most trouble prone Carter carburetor systems known. You need to pick what induction you want to use (YJ, XJ, Motorcraft 2V, Holly-Weber 2V, Clifford, Offy, or ???)?
The 88 4.2 block is (should be) a wide deck 258 casting that will bolt up the 87 head with no machining or treatment of the head's water jacket ports.
The 87 head will bolt up, but the 88 YJ intake may need some help port matching and setting the intake on the alignment dowels.
The YJ exhaust manifold should be thrown away, and the XJ header is not much better (flows way better, but prone to crack #6 pipe). You need to plan a header & exhaust.
The YJ accessories may need to change depending on the belt setup and intake used. The CJ/YJ v-belt water pump turns backwards from the XJ/YJ serpentine belt pump (get the right pump). If you have the flat belt, you can ignore this part of the swap questions.
Making the swap emissions legal may be difficult (depending on your state). The 87 MPI will probably make the best power (over the YJ carb, or even a Holly-Weber), but most emissions laws prohibit swapping in an earlier year engine control system (even if it is likely to be cleaner).
You can swap in the 87 head, and keep the balance of emissions and induction stock 88 YJ, with port matching and a header. How it will run, the gain from the 4.0L head, may not be worth the effort unless you swap in a better carb or injection and improve the ignition system. The 4.0L head swap, alone, is better than replacing a YJ 4.2 head (if damage is motivating the replacement of the YJ head). If you want more power, start looking for an HO head and the MPI system from a later YJ (both more power and emissions legal).