Does Hong Kong have the right to hold a referendum for independence? I am wondering if there was some kind of legal agreement when Hong Kong was ceded to China by Britain that guaranteed that Hong Kong could ask for referendum for independence? If there were no such agreement, can any state or province ask for independence? What are the international laws that establish which entities can hold a referendum for independence?
There is no provision in the Sino-British Joint Declaration for an independence referendum. Indeed it explicitly states "The Hong Kong Special Administrative Region will be directly under the authority of the Central People's Government of the People's Republic of China". There is no constitutional way for Hong Kong to become independent (except through modification of the constitution, which would be a matter for the Central Chinese Government, and not Hong Kong)
In general, under the principals of international law, states are sovereign. A region or province has no standing in international law. A province has no right in international law to hold an independence referendum, it is purely an internal matter for the sovereign state. A province may hold a referendum anyway, but it cannot then claim some international principle that would force a sovereign state to recognise the referendum. See Catalonia or Kosovo for more details.
According to generally accepted principles of international law, no, Hong Kong has no right to self-determination. The current internationally accepted principle of international was established in 1998, when the Supreme Court of Canada considered the question of a region's right to secede unilaterally in the case Reference Re Secession of Quebec,  2 SCR 217.
The court found that:
The various international documents that support the existence of a people's right to self-determination also contain parallel statements supportive of the conclusion that the exercise of such a right must be sufficiently limited to prevent threats to an existing state's territorial integrity or the stability of relations between sovereign states.
Quebec does not meet the threshold of a colonial people or an oppressed people, nor can it be suggested that Quebecers have been denied meaningful access to government to pursue their political, economic, cultural and social development. In the circumstances, the "National Assembly, the legislature or the government of Quebec" do not enjoy a right at international law to effect the secession of Quebec from Canada unilaterally.
Although the ruling was made by a national court, it has since become a principle of international law widely accepted globally: see, e.g., Malcolm N. Shaw, International Law, 8th. ed., Cambridge University Press (2017).
By this line of reasoning, one would find that Hong Kong residents are represented in the Chinese national government at a level on par with other Chinese citizens, and Hong Kong is surely not denied due representation in the central government. Hong Kong is represented in the National People's Congress (there are currently 36 delegates) and its Standing Committee, in which all governmental power in China is vested. Hong Kong is also represented in the Chinese People's Political Consultative Conference, which forms an important part of national policymaking in China.
Surely, one may find the selection process of these delegates to be very undemocratic, but what is important here is that the representation of Hong Kong residents and residents of other parts of China in the NPC is comparable. In fact, Hong Kong has a higher representation in the NPC than other parts of China: Hong Kong represents about 0.5% of China's population, but delegates from Hong Kong makes up 1.2% of the NPC.
There have also been Hong Kong residents representing China in international roles: Dr. Margaret Chan was nominated by the government of the PRC for, and was elected as, the Director-General of the WHO, a position which she served in from 2006 to 2017.
Overall, Hong Kong is well represented in Chinese governmental agencies that have jurisdiction over Hong Kong (i.e., the National People's Congress and its Standing Committee), and there have been Hong Kongese people representing China globally as well.
Of course, this is not to mention that it is generally accepted that Hong Kongese people do not constitute a "people" separate from the dominant Han Chinese ethnicity; some independence activists in Hong Kong do argue this, but their claims are not accepted even by many similarly minded people.
There are no Hong Kong residents selected to other governmental branches, e.g. the Supreme People's Court, but for a good reason: they have no jurisdiction over Hong Kong whatsoever. According to the Basic Law of Hong Kong, within the Chinese central government, only the NPC and its Standing Committee can promulgate laws and ordinances in Hong Kong.
If there were no such agreement, can any state or province ask for independence? What are the international laws that establish which entities can hold a referendum for independence?
As others point out, there is no such agreement in this specific case. There is, however, General Assembly resolution 1514 entitled: Declaration on the Granting of Independence to Colonial Countries and Peoples. I will quote an excerpt, the full text may be found in the link:
And to this end
The subjection of peoples to alien subjugation, domination and exploitation constitutes a denial of fundamental human rights, is contrary to the Charter of the United Nations and is an impediment to the promotion of world peace and co-operation.
All peoples have the right to self-determination; by virtue of that right they freely determine their political status and freely pursue their economic, social and cultural development.
Inadequacy of political, economic, social or educational preparedness should never serve as a pretext for delaying independence.
All armed action or repressive measures of all kinds directed against dependent peoples shall cease in order to enable them to exercise peacefully and freely their right to complete independence, and the integrity of their national territory shall be respected.
Immediate steps shall be taken, in Trust and Non-Self-Governing Territories or all other territories which have not yet attained independence, to transfer all powers to the peoples of those territories, without any conditions or reservations, in accordance with their freely expressed will and desire, without any distinction as to race, creed or colour, in order to enable them to enjoy complete independence and freedom.
Any attempt aimed at the partial or total disruption of the national unity and the territorial integrity of a country is incompatible with the purposes and principles of the Charter of the United Nations.
All States shall observe faithfully and strictly the provisions of the Charter of the United Nations, the Universal Declaration of Human Rights and the present Declaration on the basis of equality, non-interference in the internal affairs of all States, and respect for the sovereign rights of all peoples and their territorial integrity.
Based on the above declaration, one might argue that it's not as clear-cut as James puts it. On the other hand, the claim he refers to seems to contradict that self-determination right. As such, to say definitively if the right to self-determination trumps China's claim it may well have to be put before a court of arbitration (e.g. the PCA in The Hague).
For completeness, China rejected Hongkong's right to self-determination in 2018. From the South China Morning Post:
A senior Beijing official said on Friday that calls for “self-determination” were no different from the advocacy of Hong Kong independence, and the recent election bans issued by the city’s officials were totally in line with the law.
Li Fei, chairman of the Basic Law Committee under China’s top legislative body, the National People’s Congress Standing Committee, made the remarks almost a month after Demosisto’s Agnes Chow Ting was banned from contesting the Legislative Council by-election in March on the grounds of her party’s calls for self-determination.