Why same output address is invalid in a transaction on Bitcoin Core?
It is not invalid.

The code you are looking it is unrelated to validation and relay of actual transactions. You are looking at the code for RPCs which are just things for users. The RPC disallows sending to an address multiple times because this is not efficient and usually a mistake by the user.

But this is only for creating a raw transaction using the Bitcoin Core RPC. A transaction received over the network or in a block that has dupllicate addresses in the outputs would not be rejected or be invalid in any way.