The boy - who cannot be named for legal reasons - risked his life to have the snap taken for a Facebook page. He was told his actions amounted to 'total stupidity'.
The planking 'craze' involves lying horizontally in strange locations and uploading photos to Facebook and special planking sites.
The court heard that the teen was pictures with his head on one rail and his feet on the other as a train hurtled past just a few yards away.
The picture then appeared on the York Planking Association Facebook page, where it was seen by a member of the public who reported it to the British Transport police resulting in the boy's arrest.
The court's Chairwoman Francesca Horsfield told the youth: "You could have caused untold grief to your family and others, not least a train driver who would have had the awful experience of seeing you die in a horrendous manner."
The boy replied: "You don't realise what you're doing until you've done it, it's not funny when you look at it again."
He admitted trespassing on the East Coast Main Line, near York station and was given a four-month referral order.
Have you caught your kids 'planking'? Or have you warned them of the dangers of it?
Suggested For You
Get top stories and blog posts emailed to me each day. Newsletters may offer personalized content or advertisements. Learn more