Is it compulsory to use subject in a sentence e.g "going up the hill,an old temple was seen" can we say going up the hill, they/we/he/she etc saw an old temple? or is it correct without subject?
Welcome to the wonderful world of dangling participles, meaning a participle that cannot immediately be attached grammatically and/or semantically to the closest noun or pronoun not in the possessive case.
You have attempted to attach a participle to an unstated passive agent, thus suggesting that the old temple itself was climbing the hill. Merely because this absurdity forces your sentence to be deciphered as "whoever was walking up the hill saw the old temple" doesn't make it a well constructed, grammatically correct sentence.
Built in the early eighth century, the temple has been visited by countless tourists.
Going up the hill, we paused for a moment to look at the old temple.
In these examples, the participles attach to the following noun or pronoun, thus no ambiguity or unintentionally comic effects.
A simple test is to place the participle after the first available noun/pronoun and see if it makes sense, even if the style is a bit wonky:
The temple, built in the early eighth century, ...
We, going up the hill ...
So, for instance:
Just turning thirty-five today, the doctors told Karen she was cured.
The doctors, just turning thirty-five, ...
Working through the night, the composer's final draft of her piano sonata was ready for publication.
The composer's, working through the night ...
The composer's draft, working through the night, ...
None of the choices in italics make any sense, meaning the sentence must be recast to avoid the dangling participle.
The answer to your question is that it is not compulsory to attach a noun to a participle, that you will hear native speakers doing so very frequently, even in the most formal contexts, and that you will read examples of dangling participles in even the otherwise most pedantic writing.
But you will really annoy some people, and as @KarlG points out risk ambiguity and unintentional comic effects.