Refinancing before and after a 1031 exchange are viewed differently by the IRS. Refinancing immediately before a 1031 starts is a good way to get heartburn from the IRS. The IRS has an extreme dislike for refinancing before an exchange. Refinancing after a 1031 is a different story. In a refi after a 1031 you are not accessing gain, you are borrowing against equity in a property you are holding for productive use. Which is the whole point of a 1031.
A short disclaimer though. If the IRS thought you were a bad actor and wanted to get at you anyway, could they challenge a refi done immediately after a 1031? Sure, but those instances are hard to prove and rare. Have your ducks and rationales in a row and wait until after the 1031 is complete. And always talk to your tax professional.