Can I put an iPhone XS screen on my XR?

I was wondering, as the two phones have the same dimensions, could I switch the screens on an XS and an XR? What hardware or software would prevent me from doing this?

No. Phones aren't like computers where parts are standardized. Just because they look the same doesn't mean that the connectors or other specs are the same.

Take a look at the iFixit screen replacement guides for both the XS and XR.
XS:
XR:

You'll see that they have different flex cable locations.