That's what clinical trials are for: to test the effectiveness. But sometimes, they find that it has a desirable side effect.
Minoxidil was originally used to treat high blood pressure. It was found to promote hair growth, and is now available over-the-counter in Rogaine.
Finasteride is used to treat prostate cancer. It was also found to promote hair growth, and is now marketed as Propecia.
Finesteride was not designed to treat Prostate Cancer, although it has been found to be effective for certain types of Prostate Cancer. Rather, it was introduced as a drub for Benign Prostate Hyperplasia, or non-cancerous prostate enlargement. It is a 5-Alpha Reductace II Inhibitor. It works by reducing the conversion of testosterone into DHT Type 2. A few years later the effect of DHT on hair follicle in Androgenic Alopecia was established. Many physicians began prescribing Proscar (5mg Finesteride) for the off-label use of treating hair loss. Merck then got 1mg Finasteride approved as a treatment for hair loss.
As to the effectiveness of Propecica in growing hair, well the statistics available at http://www.propecia.com/finasteride/propecia/consumer/see-the-proof/photos.jsp
Disclaimer, my family is involved in selling a competing solution.