While searching on the Internet and Quora, I found disassemblers for Pac-Man, Galaxian, and Super Mario Bros. The thing that puzzled me, was while Super Mario Bros was arguably quite a complex game for the NES, while Pac-Man and Galaxian weren't, they all had roughly the same length in assembly language. All three were more than 8 kibibytes but under 16(The actual number was 9 for Galaxian, 15 for Pacman and 16 for Mario). Super Mario Bros seemed too large to fit inside such a small space, especially when compared to Pacman and Galaxian, and on the Wikipedia article for the NES, it claimed that some NES games reached 1 megabyte in size. And if that's true, how come Mario isn't bigger than 16 kibibytes(especially for the even more complex Mario games like SMB3 that came after)?
Those numbers are not correct. Super Mario Bros had 40 KiB of total ROM (32K PRG-ROM (program ROM) and 8K CHR-ROM (character ROM, for storing graphics data)). Pac-Man had 24K (16K PRG, 8K CHR). Super Mario Bros. 3 had 384K total (256K PRG, 128K CHR). Some games were even bigger (and a even few exceeded 1MiB, as you mentioned in your question).
There were several factors influencing cartridge size. The most obvious one was cost: bigger ROMs were more expensive (and games released later tend to be larger because the price of ROM was falling). Another factor was address space limitations: the NES could only address 32K of PRG-ROM and 8K of CHR-ROM, but this limit could be circumvented by using a memory mapper to swap regions of ROM in and out of the addressable range.