We assume that both transactions are valid before being in a mined block. If transaction 2 has eg. a higher fee, how do the network/miners handle it?
There are various possible scenarios:
RBF disabled, transaction 1 broadcast several minutes before transaction 2:
Transaction 1 will already have spread throughout the network and be in most/all nodes' mempools. Transaction 2 will be rejected by the majority of nodes as an attempted double spend, regardless of the fees. It would be highly unlikely for transaction 2 to be confirmed.
RBF disabled, both transactions broadcast at the same time:
Both transactions will spread throughout the network. Some nodes will accept transaction 1 and some will accept transaction 2. For the majority, this will be based on which one they see first, and not on the fees. Which transaction ends up being confirmed will be down to a combination of which one pays the higher fee, how much hashing power sees each transaction, and luck.
RBF enabled:
Transaction 2 will replace transaction 1 if it pays a higher fee, otherwise it will be rejected.