If I install macOS Mojave to an external USB drive using computer A, can I then use that drive and macOS installation on a computer B with different hardware? And then back on computer A? Even if possible, is it risky or il-advised?
Yes, you can do this confidently. It is neither risky nor ill-advised. It has been very well supported since the very earliest days of the Macintosh platform.
The only gotchas to be wary of is that you need to use a version of macOS that supports whatever machines you want to use it on. In some cases, if a new model of Mac comes out after, say, macOS Mojave 10.14.2 ships, that new Mac hardware might require a special version of 10.14.2 that has a few extra drivers and bug fixes that the general public release of 10.14.2 didn't have. So sometimes you have to make sure that you're installing that special version of macOS (in this example 10.14.2) on that external mass storage device. Then, once the next macOS update ships (in this example 10.14.3), it will have all the special pieces that were required by that new hardware, so you no longer need a special version to boot that hardware; you can just use the publicly released 10.14.3.