A few things come to mind.
But in general is reads like a flow issue.
Have you checked which code is in the history from the CEL
Most likely it is that ECT sensor is to high
Gauge uses a different sender than computer for engine temp.
So High temp gauge AND CEL would mean engine is actually running hot.
Does the heater get hotter when this happens or cooler?
Flow issue could be Radiator is getting clogged up.
Warm up engine and rad.
Leave engine running
Squeeze upper rad hose, then squeeze lower rad hose
They should have the same pressure
Now have someone raise RPM to about 2,500
Repeat the squeezing test
If lower hose gets softer then rad is getting clogged up.
Shut off engine
Remove the two fan shroud bolts and lean fan shroud back out of the way.
Run your hand across rad fins, side to side and up and down
If you feel a cool spot then that area is clogged.
Rad will/should be cooler at the bottom, but there should be no cool spots.
If there are cool spots then rad needs to be replaced, flushing can't open clogged tubes.
Another flow issue can be caused by water pump impeller blades wearing down.
This is caused by electrolysis, which gets worse if coolant isn't changed regularly.
Impeller blades get smaller and smaller, so circulate less and less coolant, this is first noticed at higher speeds, same as a clogged rad.