I second @viscous' opinion that you'll need to change out the charging port flex cable assembly. There's a sensor on it that has failed and replacing the assembly will almost certainly fix the problem. Sorry to say iFixit doesn't have a guide for that repair (at least not yet), but the Spanish site Nadie Me Llama Gallina has just what you need. No worries if you don't speak Spanish; if you use it with the Chrome browser's translation feature it's quite usable and well done.
[link|https://www.nadiemellamagallina.com/en/manuales/smartphones-1/apple-5/apple-iphone-13-pro-max-1324/flex-de-carga-11942|Manuals / Apple iPhone 13 Pro Max / Charging Flex|new_window=true]
You can support iFixit's repair efforts by purchasing the part right here on their website if you want.
[product|IF262-067|iPhone 13 Pro Max Lightning Connector Assembly|new_window=true]
For those more budget constrained, you can also purchase this part on the major sites like Amazon, eBay and AliExpress, among others. Here's an example that came up on my admittedly cursory search.
[link|https://www.amazon.com/YWLRONG-Connector-Charging-Replacement-Charger/dp/B0CGJGPKZ6|Amazon.com: YWLRONG Dock Connector for iPhone 13 Pro Max Charging Port Flex Cable Replacement for iPhone 13 Pro Max USB Charger Dock Board Connector with Tools : Cell Phones & Accessories|new_window=true]