Green Shinto friend, Paul Carty, has written in with information taken from the Seven Lucky Gods of Japan by Reiko Chiba (Tuttle, 1966). It’s a short book which looks at the origins.
The first recorded mention apparently is 1420 in Fushimi (in modern-day Kyoto), where some kind of procession of the gods was held in imitation of a daimyo procession. Then in the 1470-1480 period, bandits dressed up as the gods and tricked people into giving them money!
The key event was a conversation that took place in 1620 between Iemitsu and Tenkai, a top Tendai monk. Tenkai said there were seven qualities of nobility, which are the possessions of one who is god-like. (Iemitsu was much concerned with the deification of his grandfather, Tokugawa Ieyasu.) The qualities were as follows: longevity, fortune, popularity, candor, amiability, dignity and magnanimity.
Iemitsu liked Tenkai’s theory and asked the monk to pick seven gods who typified the qualities, then gave his authority to institute and formalise their worship. This was duly carried out and Tenkai commissioned one of the top Kano artists to paint the seven gods.
(N.B. Mark Schumacher’s website gives some alternative suggestions to this narrative at this link. He also explores the human fascination with ‘lucky seven’, attributing this to the seven-star Big Dipper and the seven planets visible in ancient times, though personally I would have thought the seven days in the moon’s quarter was a decisive factor. It’s why we have the seven-day week, after all.)