This short expression is used to express danger. Literally, it means to use fire as a toy, which can, of course, be dangerous. So, we may hear a worried mother say something such as, “Jack! Don’t play with fire!”
The expression can also be used figuratively to mean doing something dangerous or risky. In this way, buying stocks in an unknown company is playing with fire. Likewise, you would be playing with fire if you decided to eat 3-day-old fish!