Russell Borogove's answer gets to the root of the issue. They wanted minimum 6 engines on the BFS, which meant that the BFR had to have several times more, and they picked the number 31.
31 nozzles, however, is not a record. The Soyuz has 5 cores. The centre core has 4 main and 4 vernier nozzles, and the side cores have 4 main and 2 vernier nozzles each, making a total of 20 main nozzles + 12 vernier nozzles = 32 nozzles. That's a total of 32 nozzles and combustion chambers, but each core has only one set of turbopumps, so they are usually counted as one engine per core for a total of 5.
The Russians / Soviets have a history of making engines comprising a single turbopump feeding 4 main combustion chambers (and sometimes some vernier combustion chambers.) The reason they do this is to avoid the problems of combustion instability that come with very large combustion chambers. It probably also saves on tooling costs and on development costs.
The largest of these 4 combustion chamber designs is the RD170 / RD171M. Smaller 2 chambered and 1 chambered derivatives have been made. The Energiya Uragan was a proposed rocket comprising a central core surrounded by eight boosters each with one RD170 engine. Including the 4 nozzles on the central core, it would have had a total of 36 nozzles. Unfortunately this design coincided with the collapse of the Soviet union, and in the political and economic turmoil the space program was shelved.
The Saturn V's F1 engine (6770kN thrust at sea level) had by far the largest combustion chamber of any liquid fuel rocket engine, and was completely unthrottleable. The next largest combustion chamber is found on the RS-68 (single chamber, 3137kN thrust at sea level, used on the Delta IV.) That's about 4 and 2 times larger than the raptor (1700kN thrust at sea level) respectively
Therefore, attempting to develop a throttleable combustion chamber much larger than Raptor would have been a completely new engineering challenge, and not one Spacex was interested in - they are interested in optimising thrust to weight ratio, specific impulse, and cost.
SpaceX could have taken a similar route to the Russians, and equipped the BFR with eight sets of turbopumps supplying 4 combustion chambers each for a total of 32. This would have enabled them to reduce their nominal "engine count" and retain some commonality of parts with the BFS. It would not, however have reduced the amount of piping required compared to their chosen design.
SpaceX chose instead to have 31 completely independent engines for greater failure tolerance.
People often point to the failure of the 30-engined Soviet N-1 moon rocket as a reason not to use large numbers of engines. But this was a rushed design (ultimately cancelled by the Americans getting to the moon first) and while it did have some plumbing issues, the biggest problem was trying to control all those engines with a 1960's computer, which was as dumb as a modern microwave oven, and vastly more laborious to program!
Musk believes that with modern computers, a large number of independent engines is an advantage.