Lotteries in most countries are non-profit foundations, these allow them to generate additional income so that these companies can build and program goods and services for the community.
Casinos have their lotteries, so in reality it is not about competition, it is about profitable businesses, that's all, you don't have to put apples and pears in competition... even if they are fruits.
I think what the OP is trying to ask is if online casinos could compete with national lotteries, potentially surpassing them in terms of the number of bettors. Yes, national lotteries are nonprofit, with proceeds going to government projects, but let's consider the competition aspect.
National lotteries don't innovate much; they typically run the game in an old-school manner. Despite this, private lotteries still can't beat them because people are more confident in risking their money with national lotteries. They see their bets as almost a donation due to the slim chance of winning, knowing that they are also helping the country.