cardano-cli transaction build
requires a connection to the node, to confirm a balanced transaction… while cardano-cli transaction build-raw
does not, since that subcommand doesn’t balance anything & therefore doesn’t need access to the network.
This understandable limitation was still publicly undocumented in 2022 and still might be so today; first reported & discussed here:
Soon afterward I wrote a blurb here about when you might want to use one subcommand & when the other… especially with respect to whether or not your operating environment is secure enough to handle the signing key:
Secure Transaction Workflow > FAQ > Why can’t I use cardano-cli transaction build
?