It’s impossible to install XCode without an Apple account. It’s only distributed through the Mac App Store, and downloads from Mac App Store require an Apple ID. And even XCode beta downloads are locked behind an Apple login.

You can install XCode CLI dev tools without an Apple account, which comes with clang and swift for example. With this, you can build most Mac software, but I don’t think you can run Swift tests without a full XCode.

As the sibling comment notes, you can install GCC/llvm and whatever other open source tools and build Mac software without full XCode.

You can also install Apple container support without an Apple account.

Xcode is also available as a standalone download from developer.apple.com, which requires an account too, but at least it's way more reliable than downloading from the store.