How to translate “when there’s a gold rush, sell pickaxes and shovels"?
There's an article on Zhihu with the title:
淘金先富卖铲人
The paper talks about the exact phenomenon that you mention above.

Xueqiu also ran an article mentioning this adage:

有句俗话叫“淘金先富卖铲人”，出自这样的典故：当初美国西部出现淘金热时，真正能在山沟里淘到黄金的人不多，倒是向淘金者出售铲子、牛仔裤等装备器材的商家更容易发财。


It is the exact phrase that you are looking for. It isn't widely known, though, and may take the correct context to make it well understood depending on your audience.

Some other variants:

宁做卖铲人勿做挖金人

“卖铲人”

挖金子不如卖铲子

xx如同淘金客，xx人如同卖铲人 (e.g.: 游人如同淘金客，卖耙人如同卖铲人)

淘金潮里的卖铲人

淘金热中的“卖铲人”


It is quite interesting that &quot;卖铲人&quot; has become a sort of a phrase in and of itself to talk about those people who make money off of other people's pursuits.