The rationale is that someone who is dying or believes death to be imminent would have less incentive to fabricate testimony, and as such, the hearsay statement carries with it some reliability.
In medieval English courts, the principle originated of Nemo moriturus praesumitur mentiri — "no-one on the point of death should be presumed to be lying".
An original statement made by a dead person may now be admissible under the statutory "unavailability" exception (ss.114 & 116) subject to the courts' judicial discretion (preserved by s.126) to exclude unreliable evidence (i.e. the prejudicial value outweighs the probative value).
[1] The first use of the dying declaration exception in American law was in the 1770 murder trial of the British soldiers responsible for the Boston Massacre.
The doctor's testimony helped defense attorney John Adams to secure acquittals for some of the defendants and reduced charges for the rest.