Among the digital collections accessible on line at Library and Archives Canada is the database listing Canadian Soldiers of the First World War who were convicted by Courts Martial while serving overseas.
Searchable by surname, regimental (service) number, unit and offence, the database will let you see if your ancestor was a bad boy, and exactly what he may have done to contravene the expectations of the military justice system.
When checking search results, keep in mind that soldiers moved through a variety of holding and administrative units on their way to the front lines, so a listing with an unfamiliar unit should not be disregarded as being the wrong soldier.
Looking at the Courts Martial details for The Royal Canadian Regiment, out of about 4700 who served overseas with the Regiment, there were about 170 Courts Martial, some may be yet to be counted if they were serving with another unit titles at the time of their convictions. This gives a general estimate that one in 27 soldiers, or about 3.5% of the CEF may have been sentenced by Court Martial once or more (for the infantry that is, your mileage may vary in other Corps).
The offences as detailed in the King’s Regulations and Orders can also be researched further. As with many official orders and regulations, it is often the detailed context that is paramount to understand the nature of the offence and how it relates to what may sometimes seem to be a random award of punishment. Luckily for researchers, the 1907 edition of KR&O can be found online. The LAC search help page also provides a brief outline of the offences.
The LAC Courts Martial Database can also be the starting point to order a copy of the Court Martial transcript for more detailed research. See the file reference which forms part of each detailed record on the database and the search help page for guidance on ordering a file.