Your script establishes a network connection to an Ethereum node running at Infura. This means that you can use the JSON-RPC API to send commands to the node which lets you execute transactions, check balances, etc. web3.py is using that API to let you deploy contracts and interact with them.
MetaMask is a browser extension that can also establish a connection to a blockchain node but you can't directly communicate with it through that node. At best you might be able to execute some transactions whose effects could be noticed by MetaMask and presented in its UI, but that would not actually require being connected to the same Ethereum node.
These connections are a completely different thing than a dapp connecting to the MetaMask wallet. The latter means that an app running in the browser is communicating with MetaMask directly inside that browser. Your script is not doing that. In fact, it can't because you're certainly running it outside of the browser and the browser won't normally let you interact with extensions that way.
If your goal is to execute transactions from your Python script then MetaMask does not really need to be involved. web3.py is all you need. If you want to use the accounts managed by MetaMask, you just need to get their private keys.
See also: