How do I update macOS App Store apps to the latest compatible version?
Xcode can be updated by downloading the appropriate release from the Additional Downloads section of https://developer.apple.com/ - for Mojave, the latest compatible version is 10.3.1, or consult this Xcode compatibility table for other macOS versions (as suggested by aMike—thanks!)
It can be installed simply by uncompressing the downloaded .xip file and then dragging Xcode.app to /Applications/.