Assembly is not random. A capsid protein that simply polymerized around whatever nucleic acid was nearby would produce mostly empty shells or shells filled with host RNA, wasting the structural proteins the virus worked hard to make. Selective packaging solves this by coupling capsid assembly to recognition of a packaging signal, a short sequence or folded structure in the viral genome that is bound by a viral structural protein, usually the capsid protein itself or a dedicated packaging protein.
The logic is a hand-in-glove fit. The packaging signal is present only on the viral genome, so when the structural protein binds it, the resulting nucleoprotein complex becomes the nucleus for further capsid assembly. Genomes that lack the signal, including host mRNAs, are not recruited. In many RNA viruses the same protein that recognizes the signal also forms the capsid, so recognition and assembly are physically linked. In DNA viruses the genome is often inserted into a preformed procapsid through a portal, a dedicated channel that uses ATP to thread the DNA inside.
The consequence is that a productive infection yields mostly full, genome-containing particles. The fraction of empty particles that does appear is a byproduct of assembly that ran without a genome, not the intended product, and it is usually non-infectious because it cannot deliver a genome.