A photo posted online of the incident, which took place in Trowbridge, Wiltshire on Saturday afternoon, has since gone viral on social media.
Tim Brown, who took the photo, said when he challenged the boy's guardian he was told he was a "do-gooder".
Mr Brown, from Birmingham, described it as "absolutely unbelievable".
He said when he explained to the man, who was also with two young girls, that "people are seriously injured and die doing this", the man replied "the train's not due" and "he only wants to look at the track".
Mr Brown, who works for Network Rail, said he pointed out that freight or unscheduled trains could pass through at any time and he reported the matter to a guard.
British Transport Police confirmed it had been notified and was awaiting further information prior to launching an investigation.