This paper considers an indoor smart radio environment (SRE) where a Base Station (BS) communicates with a set of user equipment (UE) in the sub-THz band by reconfigurable intelligent surfaces (RISs), as the direct BS-UE links are obstructed. Motivated by the sparsity of the sub-THz channel, we model each RIS as an electronically steerable reflector, which can be described by a single parameter, i.e., the steering angle. We focus on the case where the positions of the UEs are unknown and have to be estimated. Specifically, we propose a novel approach to use RISs for jointly localizing the UEs and optimizing the communication performance. The UE localization is made possible by a dedicated RIS and is handled by a machine learning (ML) algorithm, which exploits the signal transmitted by the UEs and received at the BS. Once the estimates of the UE positions are available, the downlink communication between BS and UEs is optimized by properly selecting the electronic steering angle of the RISs so as to maximize the network throughput. By numerical simulations, the paper shows how the system performance is affected by the area of the RISs, by the number of antennas available at the BS, and by the number of steering angles scanned by the RIS used for localization.