The simple answer to this is that both Israelis and Palestinians hold the city in very high importance, due to its religious significance. Israel is a Jewish state, and the Palestinian Basic Law defines Palestine as an Islamic one. That's not to say the terms mean the same thing in practice or even in how they're used; given the divide between Fatah and Hamas (the latter running Gaza), and even the text of the Palestinian Basic Law, there are a lot of differences between the two, but that would be an answer in and of itself (and would also have to focus on what it means to be a "Jewish state", which could stretch into books-long debate). At its core, however, Jerusalem is by default a very important city for its religious significance alone.
That isn't its only significance, however. Jerusalem is also a large city, relative to the area anyways, and holds significant economic significance. Back in 1947, when the UN proposed a partition plan to create a Jewish and Arab state (this was not implemented, for the record), the population of the British Mandate of Palestine was roughly 1.8 million. The proposed City of Jerusalem, which would be under an international trusteeship, was going to have over 200,000 people, or over 10% of the population of the entire area. To put that in context for a US perspective, Jerusalem's population relative to the total British Mandate was the same as California's population relative to the United States. As you can imagine, that's a pretty big "prize", so to speak, and that's even if we didn't include the religious significance. Economically speaking, the Jewish State would have a revenue of 4.8 million pounds, an expenditure of 8.4 million, and thus a deficit. However, much of this deficit would go away, the UN report assumed, if security was not such an issue because the conflict was resolved. The Arab state would have a 1.5 million pound revenue, and 9 million pound expenditure, which also would be ameliorated by security spending and also by the ability of Arab cultivators to up production and end food subsidies. Jerusalem alone would have a revenue of 1.1 million pounds, and expenditures of 3 million. That should give you a sense of its economic significance; it would make up more than 10% of expenditures as they stood (not accounting for the assumed reductions in all areas), and 13% of the revenue. You get the drill by now; Jerusalem is a big, economically and religiously important city, and that was as clear back in 1947 as 1967 as 1987 and so on.
That said, Israelis and Palestinians aren't the only ones who wanted to control Jerusalem. For example, Jordan also sought to control Jerusalem and at points, even the entire British Mandate. Jordan was even tentatively prepared to consider a partition agreement with a Jewish state in part of the British Mandate and Jordan taking over the rest of the territory, though the agreement never came to fruition in the frenzy that led up to the Arab rejection of the UN Partition Plan and the resulting war.
Following the war in 1948, Jerusalem was divided. The predominantly Jewish Western half of Jerusalem, developed significantly by Jews in the previous half-century, became part of Israel. But the eastern half, which was held by Jordan, contained both large Arab neighborhoods and also the Old City, with all the attendant religious sites. Israel had fought to try and take the city before any ceasefire was signed, but failed in its bid to do so; some point out that the reason the West Bank has what looks like a V-shape that ends in Jerusalem is because of the huge push by Israel to make a beeline towards Jerusalem in the 1948 war. However, during the 1948-67 period when Jerusalem was divided, Jews were largely not able to pray in Jerusalem due to the division itself. As a result, Jerusalem continued to be a huge flashpoint; a military procession near Jerusalem could inflame tensions and create fears of an invasion by either side.
Palestinians were not forgetting their desire to control Jerusalem either, though their leaders primarily focused first and foremost on their desire to destroy Israel, viewing that as the path to a state of their own. Frankly, Palestinians were thoroughly demoralized and defeated militarily following both the crushing (by the British, primarily) of the 1936-39 Revolt, and later by the loss in the 1947 civil war and 1948 Arab invasion of Israel that started about when Palestinian Arab militias were being routed by Jewish forces. As a result, many relied on state sponsors (like Syria, Egypt, or Jordan) for support in fighting Israel, and also turned to guerrilla tactics and eventually international terrorist attacks in the post-1967 period especially. But leading up to 1967, Palestinians maintained their desire for a state of their own via the destruction of Israel. The Palestine Liberation Organization, or PLO, would come to dominate the Palestinian movement after 1967. But it, and other Palestinian groups and umbrella organizations, remained laser-focused on Jerusalem's importance too. The 1964 PLO Charter, back before it was overtaken by Fatah post-1967 (Fatah runs the West Bank today) and was more of an Egyptian proxy, did not specifically refer to Jerusalem, but did refer to the "liberation of Palestine" that would include Jerusalem, and to the need for safeguarding the Holy Places of the land. The 1968 PLO Charter was largely the same, and again eschewed references to Jerusalem directly, but had the same liberation language and Holy Places language. It is thus clear that Palestinians at the very least were consistent in imagining Jerusalem as part of their state, and it's hard to imagine any other city could serve as capital for Palestinians or Israelis, considering the importance of the city. It's never really seemed like a question.
In 1988, the Palestinians finally formally lodged a declaration of independence, proclaimed by the PLO. Since then, the head of Fatah and the head of the PLO has also taken the name "President of Palestine", the first being Yasser Arafat and the second (still in office now) being Mahmoud Abbas. Of course, the Palestinian Authority was created in the 1990s, and being head of that is yet another position that is held by the head of the PLO and head of Fatah. The declaration, as a formal statement of independence in theory though not in practice, finally formally defined the capital of the state as Jerusalem. It does not formally state borders, but it is clear on this capital statement. The lack of a statement on borders thus made possible the eventual Oslo agreements, in which the PLO recognized Israel's right to exist; the PLO did not claim the entirety of Israel outright in the declaration after all. Eventually, the Palestinian Basic Law would also enshrine (in 2003) that the capital of the state would be Jerusalem, unsurprisingly, in Article 3. Israel, for what it's worth, has long maintained that Jerusalem is its capital, even while it was divided, and placed many of its government buildings in West Jerusalem even while divided. The Knesset, or Israeli Parliament, was moved to Jerusalem back in December 1949, moving from Tel Aviv to there once it became clear that Israel would maintain control of that area following the end of the 1948 war. Over the next few years, all government ministries would move there besides the IDF headquarters, which would remain in Tel Aviv (likely in part due to the need to keep it far from enemy control, even moreso than civilian government buildings, and due to bureaucratic intertia). Israel's First Prime Minister, David Ben-Gurion, discussed it in the Knesset in December 1949 and put it thus:
In the stress of war, when Jerusalem was under siege, we were compelled to establish the seat of Government in Ha'Kirya at Tel Aviv. But for the State of Israel there has always been and always will be one capital only - Jerusalem the Eternal. Thus it was 3,000 years ago - and thus it will be, we believe, until the end of time.
I think this explains how both parties view the city's level of importance, though they have different types of claims and histories as different nations, of course.
Hopefully that gives you a sense that both parties have claimed the city and it has always been implied that they both wanted it as a capital (neither was happy with the plan to internationalize it, though Jewish leaders largely accepted and Palestinian Arabs largely rejected the partition plan in 1947 that contained that), and it is important both economically and religiously. Its division from 1948-67 did not leave anyone fully happy, and while Jordan has long since given up an attempt to really control the West Bank (having renounced claims in 1988), even Jordan and other Arab states have at one point sought to control Jerusalem. With a city that important, it should be no surprise that both Israelis and Palestinians have long wanted it for a capital.