Given that the two major parties (Republican and Democratic) tend to (again, speaking generically) be diametrically opposed to each
They aren't. They represent the edges of the overton window in the U.S., but when compared to other countries and ideologies, then their ideologies are still rather close together. Like the Republican RomneyCare became the model of the Democratic ObamaCare and despite the republican party moving ever further to the right the democrats are still willing to cooperate with them, because on the issues they often aren't far away from each other. Like it's often joked that the U.S. has a right wing and a far right wing party, but there's a whole other side of the spectrum that isn't really covered and which would be the diametrically opposed.
The term 'Libertarian' is fuzzy, and the ones that find the Republicans appealing are merely adhering to one definition of libertarianism in the US and don't represent all libertarians.
Definitely that one. Like classical Libertarianism was floated as a more palatable alternative for the term "Anarchism", because it focuses less on being opposed to rulers, which is often confused by opponents as being opposed to rules and instead puts the focus on "liberty/freedom" which has the same effect (no rulers=more freedom) but might have had less of a stigma. Also by Anarchism I mean the real, original anarchist movement, the one that opposes all social hierarchies. Which crucially makes them anti-capitalist as economic inequality is also a plainly obvious way to command other people to your will and against theirs. And with increased political participation, this antagonism to the exploitation of economic inequality was not just a side note, but a rather important part of that idea.
And for those reasons "right-libertarianism" or what is called "libertarianism" in the U.S., actually makes no sense in the framework of classical libertarianism, like at all. It's almost as if it is a completely different thing that just co-opted some of the original Libertarians terminology... and that's precisely what apparently happened.
Unlike classical Libertarianism/Anarchism, which exists since the 19th century under that label, the U.S. version only came into being in the latter half of the 20th century. Apparently the New Left and anti-war movement gained so much traction that, that a group of conservatives tried to get into that wave of populism and rebranded their "Old Right" ideas of "classical liberalism" and anti-interventionism as "libertarianism". Like the founder was literally previously a former member of the Republican party and their ideological base in in Austrian School economics (Anarcho-Capitalism), drawing inspiration from Murray Rothbard and Lew Rockwell. Who themselves even came up with idea of paleolibertarianism a mixture of right wing-libertarianism and paleoconservatism so "socially conservative and fiscally conservative". Implying that at least to them the economic "Old Right" part is what mattered and what they wanted to propel into the "New Right" and the rest is just baggage.
Now anarcho-capitalism, the founding ideology of the libertarian party, is so absurd that even it's followers ended up being a minority in their own party. Like when classical anarchism exposes an antagonism against the state, it's usually because anarchism is literally "against rulers", so they are fine if society is transformed from a top-down hierarchy to a bottom-up self-organization. While for anarcho-Capitalists "the state" is not the concept of rulership over a group but a concrete central government. If the same sort of power falls into the hands of a private individual, like because they bought it, that person could have tyrannical free reign, because they can decide what to do with their property and it would not be a problem to an Ancap. Though they can't outright force people, but idk hiding it in the Terms of Service is fine and if you own the media, the education system, the military or the health care sector you can make people sign contracts quite easily...
Now while in classical anarchism the absence of property or the shared ownership of crucial resources is at least in theory able to sustain itself without external force, like if someone were to acquire all they would literally be stealing from the rest who would have an incentive and a moral mandate to take it back.
The unlimited right to property, to the exclusion of others and to the detriment of others, because of it's unrestricted usage, is something that is much less self-sustaining and need enforcement. So while anarcho-capitalists already reduced anarchism to "anti-state" most of these libertarians and anarcho-capitalists ended up not even being anti-state. As they ideologically needed a state to enforce property rights. Of course you can fend others off with your private nukes, be a feudal landlord with your own army of slaves or hire the mob I mean "private security contractors". But that was so fringe that even the majority of the libertarians apparently were minarchists (a minimum state that defends property rights) and who achieved the Dallas accord (1974) leaving it vague in the party platform as to whether the state is the enemy. And in 2006 apparently they deleted further anarcho-capitalist details from the platform affirming the government as the protector of life, liberty and property.
So that the initial founders and ideologues were furious that it was now timid and no longer the party of market radicals, but one that tries to be inoffensive to get more voters.
So TL;DR U.S. style right-libertarians are really just "Old Right" economic conservatives (against New Deal Politics) that rebranded with catchy leftist terminology that drew from conservative voters and aimed to confuse anti-war people and push the conservative platform further to the economic extreme version of capitalism. The socially liberal part is more accidental as the extreme capitalism doesn't prescribe a social stance and so they can partner with conservatives and progressives alike as long as they are for unregulated capitalism where the Republican party is closer.