Can any tell me why am able to add a text on rectangle by double clicking on it. Instead an getting lines on the rectangle
Maybe that approach may work for other apps, but not in Figma. They exist as separate objects in Figma, so you can add a text layer above the rectangle layer.
Alternatively, you can convert the text layer into an auto layout by pressing Shift + A. That way, you can add a background fill to make it appear as a text within a rectangle.