The combinations of RAMPS 1.4 and REPRAP_DISCOUNT_SMART_CONTROLLER and REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER are about the most common and best tested ones. So likely there is no error in Marlin for them.
Likely sources for the error could be:
Random Marlin version.
Solder chips on the boards or adapter causing random errors.
Defect cabes - causiing random errors.
Defect switch - causing random errors.
Defect RAMPS or Mega.
Randomly changed pin or other file.
Likely sources for the error could be:
Random Marlin version.
Solder chips on the boards or adapter causing random errors.
Defect cabes - causiing random errors.
Defect switch - causing random errors.
Defect RAMPS or Mega.
Randomly changed pin or other file.