How to add foreign key in a table where column value can come from two different tables?
I would suggest you structure your comments like this,

CREATE TABLE comments (
   comment_id int GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
   parent_id  int REFERENCES comments,
   comment text NOT NULL
);


Then you three advantages,


you don't have the problem about having to reference sub-comments AND comments
you can go more than one layer deep
the schema between subcomments and comments is in sync


For more information see the postgresql and hierarchy badges.