To answer this question in general, it's important to note that hot tap water systems are not always considered potable in many parts of the world. In some places they don't attain or maintain a high enough temperature, and older systems (even in places like the UK) can occasionally use hot water reservoirs which are more open to contamination than cold water from the tap. So, in general, be sure that your hot tap water is actually intended to be potable and has the necessary safeguards.
TFD's answer discussed one obvious safety concern raised in the question regarding temperature. Given environmental concerns about wasting heat and energy, as well as warnings not to have scalding hot water from taps, many people tend to lower water heater temperatures as low as possible. But it's important to keep temperatures always at least above 120F (50C) to avoid conditions which can allow bad bacteria like Legionella to propagate. (Sam Ley mentioned this in comments, but to be clear -- any temperatures above 120F will cause Legionella to die off, but the question is how much time it will take if you have a contaminated water source: at 125F it could take hours; at 140F it only takes a few seconds.)
However, assuming a well-functioning water heater that is not set to an inappropriate low temperature, the major safety issue with using hot tap water for cooking or drinking is not bacteria, but other dissolved substances. Hot water will absorb any contaminants in pipelines much faster than cold water.
The main concern here is lead. Government agencies are generally in very strong agreement that one should NOT use hot tap water for cooking or drinking for this reason.
- From the CDC: "In all situations, drink or cook only with water that comes out of the tap cold. Water that comes out of the tap warm or hot can contain much higher levels of lead. Boiling this water will NOT reduce the amount of lead in your water."
- From the EPA: "Only Use Cold Water for Consumption: Use only water from the cold-water tap for drinking, cooking, and especially for making baby formula. Hot water is likely to contain higher levels of lead. The two actions recommended above [i.e., "flushing" water lines with fresh water and using only cold water] are very important to the health of your family. They will probably be effective in reducing lead levels because most of the lead in household water usually comes from the plumbing in your house, not from the local water supply."
- From a New York Times article on the subject: "Lead is rarely found in source water, but can enter it through corroded plumbing. The Environmental Protection Agency says that older homes are more likely to have lead pipes and fixtures, but that even newer plumbing advertised as “lead-free” can still contain as much as 8 percent lead. A study published in The Journal of Environmental Health in 2002 found that tap water represented 14 to 20 percent of total lead exposure."
The links have more information, but in general be aware that one does NOT need to have an old house with lead pipes for this to be a concern. Soldering in newer pipes can also contain lead which will leach into hot water much faster than cold. I think the CDC and EPA are probably being a little overly cautious here, but unless you've actually tested the water from your faucets for contaminant levels, it may be best to err on the side of caution and let the water run cold first from the tap before getting water for drinking or cooking (particularly when small children or pregnant women are involved).
For myself, I've always followed this practice and was taught it when I was very young. I also remember being told to do this for flavor reasons, which would also be very relevant for drinking and cooking. A few years ago when I had a discussion with a person who had never heard of this practice, I said we should both get glasses of hot water from the tap, allow it to cool, and compare drinking it to water drawn from tap cold. We both agreed that the hot water had more "off" tastes to it when it had cooled.
I can't say that this would be true everywhere. (I've since moved myself, and I haven't tried it again.) But if your hot tap water actually tastes different, it's clear that something is changing in it, which could involve more rapid absorption of some contaminants somewhere in your plumbing. Is this dangerous for most healthy adults? Probably not (unless you still have actual lead pipes), though again you'd need to do actual testing to know. But if my water tastes better from the tap cold, why would I use hot top water for cooking? As others have noted, it's likely not going to save you energy, and in some cases could actually be harmful.