Combat occurs only when two or more objects owned by unfriendly players occupy the same precise location in space. Combat can take place if any of them have the Kill mission set, if any has the other race set as Primary Enemy, or (for planets) if the Friendly Code is set to one of the variations of NUK or ATT . With certain exceptions, combat will not take place between any two ships or planets whose Friendly Codes match perfectly. (See Friendly Codes for more details.) Cloaking and being out of fuel can also interfere.
Some information that relates to this topic can be found on these pages:
The definitive article on combat, Master At Arms , was written in 1997 by Jan "Sirius" Klingele and is still almost 100% accurate. This is an offsite link, and Planets.nu is not responsible for the content.