How to take a medicine is actually a very complicated issue. Doctor
, pharmacists and scientists spends years of research figuring out the optimal way to take a medicine. I would recommend that you discuss this with your doctor or pharmacist if you have a specific question about a specific medication.
The study of how medicine is distributed in the body is known as pharmacokinectics. Essentially, every pill you take (with a few exceptions) needs to be absorbed into the blood stream. Much like food, your stomach needs to digest the medicine and then the intestines are used to absorb the medicine. Ultimately the medicine needs to get into the blood and then distributed to where it has its effects. Not all of the medicine that enters the stomach can be absorbed -- some medicine gets absorbed more fully than others. This is known as the bioavailability - the higher the bioavailability, the more of the medicine can be absorbed.
This is all to say that different medicines need different conditions in order to optimize the absorption (optimize the bioavailability). There are some medicines that need the stomach acid to digest them and then be absorbed -- these need to be taken on an empty stomach. Others, need food to protect the stomach from the medicine. It really just depends on the medicine and its coating.