Message “MATLAB has encountered an internal error and needs to close” is a generic error message indicating that there was an exception or problem within MATLAB that caused it to crash. This is a generic error message, and there are many possible reasons behind it. This error is also encountered with MATLAB desktop.
As while training of CNN, MATLAB online is referencing some functionality of toolbox where there is a crash. As said, there can be many possible reasons behind it (example: exhaustion of any resource)
You can try same work on MATLAB desktop and if the problem occurs again you can have a look at the crash log or crash dump file which may help you in knowing the cause of problem. The crash log/dump files can be read with a text editor such as Notepad, vi, or nano.
How do I locate the crash dump files generated by MATLAB?