I use both dry and canned food. My dog (15 years old) eats the cat food, and my cat (6 months old) eats the dog food. They both eat each other's type of food. Why does it happen, and could it be doing any harm to them? The food is in different locations.
"Why" is likely going to remain a mystery, but something about the food you have is enticing the pet for whom it's not intended more than the food that they should be eating. It's unlikely anyone can give you a truly definitive answer on that question.
"Is it doing any harm to them" is much easier to answer, and that answer is emphatically yes. Dogs and cats are different animals, with different nutritional needs, and in most cases cannot share a diet without the health of at least one of them being negatively impacted.
In the United States, the organization that sets standards for dog and cat foods is the AAFCO. While most of the free content on their website is geared toward consumers, and as such very light on detail, I was able to find a pdf from 2013 on proposed revisions to the nutrient profiles. While I can't guarantee that the data is currently up to date, it still can offer some insight into the nutritional differences between cat and dog food, using the "Adult minimum maintenance" values, based on calorie content.
Crude Protein: 45.0 g/1000 kcal for dogs, 65 g/1000 kcal for cats
In the specific listings for Crude Protein, all minimums for cats are higher than those for dogs, except Methionine, at a minimum 0.83g for dogs with no maximum compared to a minimum 0.5g for cats with a 3.75g maximum; Methionine-cystine, at a minimum 1.63g for dogs and 1.00g for cats; and Phenylalanine, at a minimum 1.13g for dogs and 1.05g for cats. Also of note that Tryptophan has no maximum for dogs, but a maximum of 4.25g for cats.
Crude Fat: 13.8 g/1000 kcal for dogs, 22.5 g/1000 kcal for cats
In the Crude Fat breakdown, while the overall minimum for cats is higher, dogs require a higher level of Linoleic acid at 2.8g, compared to cats at 1.4g. Additionally, dogs have a standard described as "(Linoleic + Arachidonic):(alpha-Linolenic + Eicosapentaenoic + Docosahexaenoic) acid Ratio" with a value of 30:1; on the table for cats, this line does not exist.
There is no single score for minerals, however, the minimum values are only equivalent for Potassium (1.5g). Dogs have higher minimums for Magnesium, Zinc, and Iodine, as well as a higher maximum on iodine; all other minerals have higher minimums for cats. Additionally, we once again see a value in the standards for dogs, "Ca:P Ratio" (2:1), which is not present in the standards for cats.
Vitamins & Others:
Here's where things get particularly interesting. In dogs, we have a higher minimum but lower maximum than cats for both Vitamin A (1250/62500 IU for dogs and 833/83325 IU for cats) and Vitamin D (125/750 IU for dogs, 70/7520 for cats); in those cases, a dog eating cat food could easily end up consuming too much or too little of either nutrient. Dogs also have higher minimums for Vitamin E, Riboflavin, Pantothenic acid, and Vitamin B12. Cats are higher on the remaining values; some values are close, but others, such as Niacin (3.4 mg for dogs, 15 mg for cats) have a more drastic divide. It's also here where we find the first entries present only for cats: Vitamin K (0.025 mg), Biotin (0.018 mg), and Taurine (extruded, 0.25 g; canned, 0.50 g).
Neither animal's minimums are consistent with each other. Nor are either animal's minimums consistently higher than the other. Nor are either animal's minimums even consistently measuring the same nutrients. While it would be possible for a company to formulate a food that could be balanced for both cats and dogs, unless it is labeled as such, a food that is balanced for dogs can not be considered balanced for cats, and one that is balanced for cats can not be considered balanced for dogs.
While a time or two will not cause problems for either animal, consistently eating the food of the other species will over time cause severe health problems due to malnutrition that can eventually lead to the premature death of that animal. If they are consistently swapping bowls at mealtime, you may need to re-evaluate the diet you are offering each to find one that appeals more to them in a species-appropriate diet, or to re-evaluate when, how, and where you are feeding them. If, as you mentioned in a comment, they are regularly eating only the "leftovers," then you should consider feeding only what they will eat in a single sitting and removing any food left after they have finished eating, in order to help ensure each animal is receiving complete species-appropriate nutrition.
It is not going to cause any harm. But both your cat and dog will suffer from malnutrition in the long run. It is because their dietary needs are different.
For example, an essential component of cat food is taurine. In it's absence cat can develop heart diseases and may go blind.
You may argue that in the streets you see cats and dogs eating everything. Well they are just surviving not thriving. Their life expectancy is much less.
So for your pet's well being you need to be strict. For example you can try this. You lock up your cat and feed the dog and then lock up your dog and feed the cat. The first few days may be difficult for them but they will get adjusted.