Solution
Generating code for a subsystem that takes input from a muxed source might cause invalid index error (2637595) while building a model for VeriStand using MATLAB R2021a/ R2021b/ R2022a.
This is a known issue and reported as a bug, MATHWorks had released patches for the following versions as below:

Navigate to External Link: Generating code for a subsystem that takes input from a muxed source might cause invalid index error (2637595) to download the patch.
Note: MATHWorks account is required to open the above-mentioned link.