In a meterpreter reverse_https session when I use the detach command it closes my current session and then creates another, what it is the purpose of this?
The payload will keep trying to connect back until
SessionExpirationTimeout is hit. Default is one week.
The payload has a hard-coded expiration date stamped into it during the initial staging process. By default, this is one week from the current date (relative to the target). This prevents a forgotten session from connecting back indefinitely. You can control this setting through the SessionExpirationTimeout advanced option.
To avoid shutting down the payload but still exit the temporary session, use the detach command from the Meterpreter prompt
SessionExpirationTimeout] option to 0 and detaching the session will instruct the payload to keep reaching out until the SessionCommunicationTimeout is hit or the process is killed.