Recent experiments showed that the linear double-stranded DNA in bacteriophage capsids is both highly knotted and neatly structured. What is the physical basis of this organization? Here we show evidence from stochastic simulation techniques that suggests that a key element is the tendency of contacting DNA strands to order, as in cholesteric liquid crystals. This interaction favors their preferential juxtaposition at a small twist angle, thus promoting an approximately nematic (and apolar) local order. The ordering effect dramatically impacts the geometry and topology of DNA inside phages. Accounting for this local potential allows us to reproduce the main experimental data on DNA organization in phages, including the cryo-EM observations and detailed features of the spectrum of DNA knots formed inside viral capsids. The DNA knots we observe are strongly delocalized and, intriguingly, this is shown not to interfere with genome ejection out of the phage.