It is an 'urban legend' that when a male virgin turns 30, he can use magic. (Note: in Japanese, different words are used for male/female virgin, and this magician thing applies only to male ones.)
According to this archived site
2001年初め (early) :自アンにて魔法使い説が認知される - "30-year-old virgin turns to a magician" theory was posted at 自アン
2002/05/14:自アン閉鎖 - 自アン was closed.
2002/08/05:2ch毒男板にて魔法使いスレ誕生 - First appearance of a thread mentioning the magician thing at 2ch.
2002/08/23:スレの杜を始めとするニュースサイトに紹介される - The thread got more publicity due to other news sites picking the thread.
I'm not sure what 自アン is, but seemingly it is an imageboard site like 2ch (currently 5ch). Anyway, over these 20 years, this has become widely known and 魔法使い (maho-tsukai = magician) often refers to 30+ year old virgin in many contexts.
This site mentions Montesquieu's Lettres Persanes as an origin of the legend. It has this in Letter 58.
Un autre vous promet de vous faire coucher avec les esprits aériens, pourvu que vous soyez seulement trente ans sans voir de femmes.
(English trans.) Another promises you the love of the spirits of the air, if you will see no women for a small trifle of thirty years.
Since nobody can be sure about what the original poster at 自アン had in mind, I guess it's hard to tell if it is originated from Montesquieu.