From 300 BC to 300 AD tattoos were used for spiritual and social purposes. Just like in other tattoo cultures, they were an indicator of ones social status.
From 300 AD on, tattoos were used in Japan to mark criminals. This practice is called bokukei or bokkei. Japan was the last country to stop marking criminals with tattoos (in 1870). People started covering up these marks of shame with more decorative tattoos and that's how the art started.
Tattooing in Japan reached its zenith in the 1800s, during the Edo period, a time when the power and influence of the common people was very much on the rise. One way in which people chose to use their new-found wealth was to celebrate their art and culture with tattoos. The beauty of the images created was considered a reward for enduring what was, at the time, a long and painful process.
Around 1870 the Japanese government outlawed tattoos in order to make a good impression on the Western world. As a result, Japanese tattoos went underground and became affiliated with the Yakuza, the Japanese mafia.
Tattooing in Japan was legalized again in 1945 by the occupying forces, but never really lost its association with crime. Even today people with tattoos are still banned from businesses like fitness centers, in an attempt to restrict the yakuza from entering their place.