The story I have always heard (I will try to find and add sources later) is that in the wake of the 1983 video game crash, which primarily affected the US, Nintendo decided to re-evaluate their North American branding, and what they decided on was to avoid as far as possible any association with the console being a toy. Thus the NES is an "Entertainment System", and the main unit is a "Control Deck". The boxy gray design with a front-loading slot lets it sit side-by-side with home entertainment hardware of the day, and the case is bigger than it needs to be, which makes it seem more substantial. The same is true of the cartridges — the Japanese cartridges are small, come in various bright colors, and have rounded edges, all of which screams "toy", while NES cartridges are oversized, use subdued colors (mostly a gray that matches the console), and are extremely angular.
It seems strange today to deliberately shy away from the appearance of fun in a video game console's marketing, but in 1985 it seems to have been the right move, contributing to a long dominance of the console market by Nintendo.
There is most definitely no technical reason. And since some NES games featured different colours than just grey (think Zelda), it can't be based on some licensing directive either.
Once the forms for the enclosure are made, there is no substantial cost in choosing any specific colour. Japanese games do show this quite nice. So there can't be no financial reason.
The same point about colours can be made for Atari VCS cartridges as well, here the overwhelming majority came in black. Similar Intellivision or ColecoVision, or various European consoles like G7000 or VC4000.
It might end up being more of a cultural/style issue, where Japanese may see colourful variations as an addition, while western gamers (or at least western management) though of them as oddities?
Maybe we need to think it from the other end: Is there any rational for game companies to make the additional effort of ordering cartridges in varying colours?
All measures, beside game development itself, are about sales and marketing. Cartridges came packed in boxes (*1), invisible to potential customers. Whatever colour they are will not have any effect on a purchase decision. The customer will only see the box - which in turn did come in quite many friendly colours. Some used to mark separate game types, while others just yelled I'm different.
Bottom line: There is no technical, legal or financial reason but maybe it was an issue not worth doing at all?
*1 - Boxes are by the way another major difference in console games in and outside of Japan. While in Japan a large number of games were sold in boxes barely bigger than the cartridge itself. Boxes outside Japan were usually comparable large, more like a book.
As said in the Raffzahn's answer, it's mostly a marketting or design choice and has no technicalities.
First, you are mistaken in beliving all western NES cartridges were gray : They were some games released in gold cartridges as well. But you're right in that it's still much less varied than the famicom which featured countless different colours.
In the west, the NES cartridges were marketted to as "game packs". In Japan they were marketted to as "casette", similarly named to the audio tape casettes, and those definitely came in all kind of colours. This tradition probably came because some other home computers at the time actually used casette tapes as storage media. This could have played a role in design choices but this is just a supposition.
You'll also notice another huge difference other than the colour : The size ! Western NES cartridges are largely oversized. They have a fixed size which is the maximum available, and usually the PCB inside takes between 1/4 to 1/3 of the available area. Only prototypes (not released to the public) and some MMC5 games uses the majority of the area, and even then, the whole area is still not fully used up.
Famicom carts can be variable in size as the load on the top of the console and can grow vertically as much as needed. As such, most games tended to be just the size of the PCB, which uses all the area. In the few cases where the PCB was larger, they made a larger game case. As such Famicom games featuring complex mappers such as MMC5 will be actually in physically larger cartridges.
Another major difference is that in the west, only Nintendo was officially able to make and sell cartridge. Some unlicenced developers broke this rule, and Tengen even had a trial against Nintendo. In Japan, Nintendo openly allowed any company to make their own cartridge, so large game companies such as Konami and Namco had their own cartridges cases, which differs significantly from Nintendo's.
My source is my experience with the NES/Famicom as well as Bootgod's cart database.