It's not "[twitter's] own data". Full fucking stop.
It's the data of the users on the platform. In the same way that the texts I send are NOT my carrier's data, and the emails I send are NOT my email provider's data, and mail I send is not the postal service's data. It's mine. They are simply holding it.
The alternative to pulling this data from the api is to simply scrape it from the site. And there are many (very legal) ways to do this. Although they come with some notable downsides (everything from forcing a user to download a browser extension, to having to ask the user for their credentials).
They also carry downsides for twitter - scraping may not be efficient for them.
So the API is the compromise: I can get access the data I could anyways using the automations I'd prefer, but in a manner that allows Twitter to moderate possible downsides for themselves.
Broadly speaking - this is the legal structure twitter (and google, and all sorts of other sites based on user content) operate under. They are not the legal publisher of the information. They may be granted a right to copy and reproduce the information to facilitate the operation of the service, but it's not their info. Period. if it were... they could be in a fuck load of hot water for anything they allow to be posted to the site.
So - while they're under no obligation to build an API... it's a compelling way to improve the user experience, moderate the consequences of scraping, and increase engagement and activity. Because at the end of the day - that information is already available to users.