It's meaning is quite plain:
He tells us that he once had a dream that it (his life) would end in the way that was about to happen (being shot by a band of Stormtroopers).
Dream is likely used to mean fantasy, whether he is meant to say it was literally a dream that occurred during sleep, a hope, or a hope expressed through a dream during sleep. (Or a dream during sleep that was expressed as a hope!)
Why did the writer of the show have the character say this? That is for us to understand or speculate about.
What I get is the idea that in the past he imagined himself dying in glory, fighting for good against evil.
Would is a modal used to mark tense: the future of the past, as it's called here:
(See Usage of Specific Verbs > Will and Would.)
To say, as in another answer, that it is an example of backshifting, seems to me a stretch, at best, or incorrect.
He is not reporting speech indirectly. That would require something like I once said that I had a dream ... ".
Consider: *The house looked ugly then, but it would get a new coat of paint a few years later.*
That is a declaration, not involving what anyone once said, (or thought, if we want to conceptualize knew in the instant sentence an act of "inner speech" that is being reported).
The reason for using would is the same. It was something that occurred in the past that was about the future at that time.