Enable Developer options, toggle this setting and check behaviour when charging, disable Developer options. Write how it turned out and do not forget to mention what version of Android you use, it is necessary to mention in every query. If you have Android 10, describe how you upgraded to it and whether you performed a factory reset.
1. Do you have screen saver "on"? 2. Can you enable Developer Settings; Settings->System->About Phone -> Software Information -> Press Build Number "many times" Check for "Stay awake" toggle, it is near the top - is it enabled? If so, disable it.
3. Could the reason be any app keeping it alive when charging? That activated this flag somehow.