Hierarchical Bayesian detection algorithm for early-universe relics in the cosmic microwave background