Whether there is any compatibility issue for PHP 5.6 and Apache 2.4.51 on Ubuntu 18.04/20.04?
Yes it is safe and you should not have any compatibilty issues when installing the version from ppa:ondrej.
sudo add-apt-repository ppa:ondrej/php
sudo add-apt-repository ppa:ondrej/apache2
sudo apt update
sudo apt install php5.6 apache2
While in general, you should be careful with PPAs, this is one of the few PPAs which I would recommend without a doubt.
Ondřej Surý is maintainer of the official PHP packages in Debian (and thus Ubuntu). He quite knows what he's doing.
This is what he says about himself on his website:
I am a Debian Developer since year 2000, and I have been packaging PHP for Debian since PHP 5. [...] the PHP packages in my Ubuntu PPA and Debian DPA matches the official packages in Debian. Basically I am saying that you can’t get any closer than that.
Regarding your concerns due to this answer: This is an 8 year old question. Back then, there was no PPA like this, and a downgrade was done manually (or with some script from the internet). You will install php5.6
alongside any other version you have. It is true, that this might lead to dependency issues. But with ondrej's PPA, you won't have the issues, as the PPA will also deliver these dependencies.