It is certainly legal to enter into an agreement with a third party to operate your business for you for some period of time. Even better, it sounds like it may have an advantage for you. My guess is that if you close the business before the end of your lease term you'll forfeit your entire security deposit. In that case the offer of the franchisor to run the business and assume all risk from now until the lease expires sounds like a no risk way to get back at least some of the deposit you paid the landlord.
As far as a legal agreement to meet your needs, it could be something very simple or fairly complex, depending on the franchisor and the attorneys involved. You should ask if the franchisor has some form of agreement stating the terms under which they will run the store for you until the end of the lease.
Also ask them to make sure the agreement clearly spells out that you will have no obligations to them at the time the business closes -- except for things like non-competes, which I'm guessing won't be an issue for you.
Once you receive the agreement, read it over carefully and make sure you don't have any questions or concerns. You might consider whether or not to pay your own attorney to review the agreement. It's safer if you do but you'll spend quite a bit in legal fees getting the review done. That's your call.
In any case, it is almost always significantly cheaper to have your attorney review a document prepared by someone else rather than having your attorney compose the original agreement, so ask the franchisor to draft something up.
Sorry to hear your business is closing but at least you're handling this is a professional and thoughtful manner.
Related: When You're Ready to Sell the Business
Related: Plan Your Exit Strategy