I had this issue for a long time. I thought it was hardware related or even heat, but it wasn’t. It’s not till I upgraded my phone, that I reformatted the S5 completely (clearing everything cache etc). Once I reformatted the problem disappeared (I also removed the memory card). I didn’t install any apps at all and the phone is just used as a spare for calls. In my opinion it is therefore app related, or an app that affects things. It is irritating to have to reformat, but it did fix the problem which was exactly the same as you described.
My phone would flicker at low manual brightness, or once the phone light fades and is about to go off, it flickers in a weird greeny/yellowy way.