You may refer to the following Bug Report which describes a similar error for "HDL code generation failure from a top-level model that contains a protected model" along with the fix options.
Also, it is to be noted that models generated in MATLAB R2021a or R2021a Update 1 cannot be used in R2021a Update2 to R2021a Update 7 and vice versa, hence it is recommended to use the same MATLAB version with which the Protected Model was generated. Please refer to the below link for more detail:
I hope this helps!
