Epic gives pretty good money to game companies to give away their games, and it's a profit for both Epic and the other game companies.
For Epic: Epic Games will attract more potential customers. That's why they especially give away free games during sales, to attract more people to buy something from them.
For Game Companies:
1- The game will live longer, the biggest example is GTA 5, many people is playing GTA 5 Online right now and put money into it, because many people also got it free from Epic.
2- Easy money from Epic Games, especially if it's an old game that everybody played (like Witcher 3.). Game companies would make more money from Epic, rather than regular game sales.
3- They could also sell more DLCs, since you got the game for free, you would want to buy DLC if it's a good game. Example: Civilization VI, DLCs are so important at that game and that game was given away in Epic Games, so many people bought the DLCs, Epic also gets some money from it.
That's why some companies are giving away their games with Epic Games.
Also, even though it's not confirmed, Epic gets shit tons of some user information, i'm saying this because Tencent Games owns %40 of Epic.