Hydrogen from dilute acids can only be replaced if electrons are supplied to H+ ions of the acid.

Metals have a tendency to lose electrons and hence they supply electrons, i.e., they are electron
donors. That is why metals displace hydrogen from dilute acids. On the other hand, non-metal is an electron acceptor. It cannot supply electrons to H+ and hence, it does not displace hydrogen from dilute acids.