Decrypting a Master Key works well using SQLCMD but not in the script
As @JohnEisbrener make me noticed in the comment, the issue is due to the fact that the script is missing of the
USE [mydatabase] statement.

So the right way to write the stored procedure variable is

SET @exec_sql = 'USE MYDATABASE; OPEN MASTER KEY DECRYPTION BY PASSWORD = N' + quotename(@dbMKey,'''') + '; ALTER MASTER KEY ADD ENCRYPTION BY SERVICE MASTER KEY; CLOSE MASTER KEY;';