The legality of Bitcoin mining depends entirely on your geographic location. The concept of Bitcoin can threaten the dominance of fiat currencies and government control over the financial markets. For this reason, Bitcoin is completely illegal in certain places.
Bitcoin ownership and mining are legal in more countries than not. Some examples of places where it is illegal are Algeria, Egypt, Morocco, Bolivia, Ecuador, Nepal, and Pakistan. Overall, Bitcoin use and mining are legal across much of the globe.
Risks of Mining
The risks of mining are that of financial risk and a regulatory one. As mentioned, Bitcoin mining, and mining in general, is a financial risk. One could go through all the effort of purchasing hundreds or thousands of dollars worth of mining equipment only to have no return on their investment. That said, this risk can be mitigated by joining mining pools. If you are considering mining and live in an area that it is prohibited you should reconsider. It may also be a good idea to research your countries regulation and overall sentiment towards cryptocurrency before investing in mining equipment.