I was having this issue with my '18 2500 for like two years and couldn't figure it out. Light was going bonkers all the time and I would loose trailer brakes. Scary stuff in the Colorado mountains. My solution came when I upgraded to a new 5th wheel. Haven't had the problem since!
Seriously though, I ended up finding a pinched wire under the trailer leaf spring. Somehow one of the wires to the electric brakes had got pinched inbetween two leafs and was shorting out. Had to cut it out and replace it. It fixed the issue and I was happy to finally determine it wasn't anything with my truck. Then I traded in that trailer like a month later.
Seriously though, I ended up finding a pinched wire under the trailer leaf spring. Somehow one of the wires to the electric brakes had got pinched inbetween two leafs and was shorting out. Had to cut it out and replace it. It fixed the issue and I was happy to finally determine it wasn't anything with my truck. Then I traded in that trailer like a month later.