One spacecraft + spacesuits became two spacecraft
When the Apollo program started, the assumption was a "direct mode" mission. This plan had no lunar module; there would only be one spacecraft which launched from Earth, landed on the moon, took off, and then returned to Earth. Two contractors with prior experience building aircraft environmental control systems (ECS) were hired: Garrett AiResearch for the ECS of command module, and Hamilton Standard to make the life support for the spacesuits.
During World War II, Garrett AiResearch built the cabin pressurization systems for the B-29 bomber, the first high-altitude bomber that needed cabin pressurization. After the war, they expanded their business to other aircraft and spacecraft environmental systems. They were the ECS contractor for the Mercury and Gemini programs. They were the natural choice to design the command module ECS.
Hamilton Standard originally made airplane propellers, but they soon expanded to other aircraft systems. In 1958, the company made the environmental control system for the Convair 880 jetliner. In July 1962, they were selected as the prime contractor for the Apollo spacesuit, with International Latex Corporation as a subcontractor for the pressure garment.
The LiOH cartridges for the spacesuits needed to be small; those for the command module needed to be large. At this time, it would have been counterproductive to try to standardize on a size or shape. So each contractor had their own team of engineers, and no need to work with each other.
NASA eventually decided on the "lunar orbit rendezvous" mode. A lunar module would separate from the CSM, land on the moon, take off, and rejoin the CSM in lunar orbit. A contract for the LM was quickly awarded to Grumman. They needed to catch up, so they subcontracted the LM ECS to Hamilton Standard, who already had their team working on the life support for the spacesuits.
The eventual canisters for the LM were basically enlarged versions of the spacesuit cartridges -- both cylindrical. Meanwhile, the square CM canisters designed by AiResearch proved successful. Trying to standardize on a design at this point would have put the whole program off of schedule.