Flag exchange at stations and crossing trains is to indicate everything is okay with the rake(like no hot axles, loose couplings, etc are visible) and has got nothing to do with the section being clear really(For example if an express is overtaking a passenger bound in the same direction even then flag exchange happens in the day and color light exchange in the night). In case of any visible problem found either by the linemen at stations who exchange flags or by crew of other trains then immediate red flag is displayed for attention of LP/ALP/Guard of the moving train.
.
This...
more... is a standard operating procedure in IR however i am not sure if it is mandatory and punitive if not obeyed. I never saw this being disobeyed though except in case of Locals/EMU/MMTS.