How can you tell when a molecule forms a lattice
There is no easy way to guess or predict the answer in general, but experience will give you some clues

The way to tell whether something is a molecule or a covalent solid (Made from a lattice) is to look up the structure. When you first learn chemistry, some things have just have to be learned. But when you learn a few things, some patterns will emerge and you will get better at predicting the properties of other compounds.

The structure will usually tell you the answer. Other physical properties of the compound can hint at the structure. Carbon dioxide is a gas so you should be able to predict it is a small molecule; silicon dioxide is a refractory solid: this is a big clue that it is not a small molecule but is, in fact, a network solid mad from a lattice of Si-O bonds. Nitrogen and Oxygen are gases, so most likely small molecules; graphite and diamond (both forms of pure carbon) are solids so  out likely networks made from large lattices.

There isn't really a simple way to predict this, but once you have learned a few examples, patterns will emerge.