They collect them in the forests on the outskirts of their towns (or buy them in a store, increasingly) and bring them home and keep them as pets. Due to the simplicity of their diet, ease of their replacement, and surprisingly, generally docile nature, they serve as a lower-investment entryway into pets for Japanese youths where a Western kid would probably end up with a hamster or something to that effect, which are great animals, but are honestly not easy to correctly take care of, and hamsters are the most abused animal in the world, but I digress.
Children fight the beetles like Beyblades, which is fun and safe for them to do; adults breed really expensive beetles and trade them on the Internet, which is unavoidable with any pastime; and (interestingly, to me at least) rural village farmers collect beetles during their off time, and then have a yearly beetle competition! It seems like it would be a one-off sort of phenomenon, but it's actually a pretty widespread tradition among rural Japan - it's a really good, tried-and-true method for breaking up the harvest season.
The beetle fights almost never end in the death of a beetle - most often, the fight ends when one beetle is no longer on the log they are fighting on, and even in unregulated rural circuits, traditional convention dictates that the battle goes until one beetle, the loser, flies away (which happens 20:1), or the loser's horn is broken, which happens in nature and heals naturally.
This is probably the most prolific source of the Japanese media trope of "fighting pets" - Pokémon creator Satoshi Tajiri famously got the idea from collecting and battling bugs as a child, even being nicknamed "Dr. Bug." Coupled with the loose tradition of eating insects, this tradition also lends toward the formulation of the common opinion, or lack thereof, of people in Asia regarding bugs. Westerners, including myself (I'm writing a webpage about it for crying out loud) often find it strange, but there is not really a cultural fear of insects in most of Asia. I envy it: I'm scared to death of bugs, despite the fundamental role they play in the ecosystem and the even more fundamental role they will play in the food palate of the average citizen of Earth in 2150. I like to think the beetle videos are acclimating me to them in general. I kinda want one.